using MathNet.Numerics; using MathNet.Numerics.LinearAlgebra.Double; using Newtonsoft.Json; using System.ComponentModel; using System.Data; using System.Drawing.Design; using System.IO; using System.Numerics; using System.Reflection; using System.Runtime.Serialization.Formatters.Binary; using System.Text; using System.Text.RegularExpressions; using static Hydro.MapViewEnum; using static Hydro.RepeaterViewModel; using Cursor = System.Windows.Forms.Cursor; namespace Hydro; //public partial class DMap : Panel //{ // private Bitmap buffer; // public DrawDelegate DrawNet = null; // public DrawDelegate DrawNetNew = null; // public DrawDelegate DrawBackGroundPic = null; // //绘制辅助线 // public DrawDelegate DrawAuxiliary = null; // public MouseDelegate onMouseDown = null; // public MouseDelegate onMouseMove = null; // public MouseDelegate onMouseUp = null; // public MouseDelegate onMouseWheel = null; // public DrawingMode drawingMode = DrawingMode.All; // private bool Inited = false; // public DrawingStatus Status = DrawingStatus.Ready; // public DMap() // { // DoubleBuffered = true; // } // //补充参数 // public void Init(TContainer TC, DrawDelegate[] Draws, MouseDelegate[] MouseEvents) // { // this.TC = TC; // this.DrawNet = Draws[0]; // this.DrawNetNew = Draws[1]; // this.DrawBackGroundPic = Draws[2]; // this.DrawAuxiliary = Draws[3]; // this.onMouseDown = MouseEvents[0]; // this.onMouseMove = MouseEvents[1]; // this.onMouseUp = MouseEvents[2]; // this.onMouseWheel = MouseEvents[3]; // this.Inited = true; // this.Status = DrawingStatus.Ready; // } // protected override void OnPaint(PaintEventArgs e) // { // this.Status = DrawingStatus.drawingBase; // base.OnPaint(e); // if (!Inited) { this.Status = DrawingStatus.Ready; return; } // if (float.IsInfinity(mapOption.zoom)) { this.Status = DrawingStatus.Ready; return; } // if (buffer == null || buffer.Width != Width || buffer.Height != Height) // { // buffer?.Dispose(); // buffer = new Bitmap(Width, Height); // } // // 使用缓存绘制,避免在每次重绘时重新计算所有要绘制的元素 // var bufferG = Graphics.FromImage(buffer); // // 先将控件的背景填充为白色 // bufferG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; // bufferG.Clear(Color.Transparent); // bufferG.TranslateTransform(Width / 2, Height / 2); // bufferG.ScaleTransform(mapOption.zoom, -mapOption.zoom); // bufferG.TranslateTransform(-mapOption.Center.X, -mapOption.Center.Y); // this.Status = DrawingStatus.drawingPic; // DrawBackGroundPic(bufferG, _Template); // this.Status = DrawingStatus.drawingNet; // //BookMark:绘制地图事件 // DrawNet(bufferG, _Template); // this.Status = DrawingStatus.drawingNetNew; // if (_newTemplate?.network != null) DrawNetNew(bufferG, _newTemplate); // this.Status = DrawingStatus.drawingOthers; // DrawAuxiliary(bufferG, null); // // 将生成的画布绘制到控件上 // e.Graphics.DrawImage(buffer, 0, 0); // bufferG.Dispose(); // this.Status = DrawingStatus.Ready; // } // protected override void OnMouseDown(MouseEventArgs e) // { // base.OnMouseDown(e); // if (Inited) onMouseDown(e); // } // protected override void OnMouseMove(MouseEventArgs e) // { // base.OnMouseMove(e); // if (Inited) onMouseMove(e); // } // protected override void OnMouseUp(MouseEventArgs e) // { // base.OnMouseUp(e); // if (Inited) onMouseUp(e); // } // protected override void OnMouseWheel(MouseEventArgs e) // { // base.OnMouseWheel(e); // if (Inited) onMouseWheel(e); // } //} partial class DMap { #region 核心属性 public TContainer TC = new TContainer(); /// 地图选项 public MapDimensions mapOption { get { return TC.mapOption; } set { TC.mapOption = value; } } /// 临时管网层 public Template _newTemplate { get { return TC.newTemplate; } set { TC.newTemplate = value; } } public Template _Template { get { return TC.template; } } #endregion } public enum DrawingMode { All, Pic, Net, New, Auxiliary } public enum DrawingStatus { drawingBase, drawingNet, drawingNetNew, drawingPic, drawingOthers, Ready, } public class MapOption { public float Link_multiply { get; set; } = 0.6667f; public float junction_multiply { get; set; } = 1f; public bool _ShowValve { get; set; } = true; public bool _ShowJunction { get; set; } = true; public bool _ShowStatus { get; set; } = false; public bool _ShowFlowDirection { get; set; } = false; } //public partial class MapViewer : UserControl //{ // #region 一、全局 // #region 初始化 // private bool _showToolBar = true; // [DisplayName("显示工具栏")] // public bool showToolBar // { // get // { // return _showToolBar; // } // set // { // _showToolBar = value; // if (this.panel1 != null) this.panel1.Visible = value; // } // } // public MapViewer(bool showToolBar = false) // { // this.showToolBar = showToolBar; // InitializeComponent(); // MapCenter = PointF.Empty; // zoom = 1.0f; // DoubleBuffered = true; // SetStyle(ControlStyles.SupportsTransparentBackColor, true); // BackColor = Color.Transparent; // } // public MapViewer() // { // this.showToolBar = false; // InitializeComponent(); // MapCenter = PointF.Empty; // zoom = 1.0f; // SetStyle(ControlStyles.SupportsTransparentBackColor, true); // BackColor = Color.Transparent; // } // public void SetEditMode(bool isEditMode) // { // _IsEditMode = isEditMode; // } // private void MapViewer_Load(object sender, EventArgs e) // { // GlobalObject.PropertyForm = this.propertyForm; // this.panel1.Visible = _showToolBar; // cb_Node_Colour.Items.Clear(); // cb_Link_Colour.Items.Clear(); // cb_Link_Colour.Items.Add(ColourType.无); // int i = 0; // foreach (ColourType colour in Enum.GetValues(typeof(ColourType))) // { // if (i <= Colour.NodeTypeCount) // cb_Node_Colour.Items.Add(colour); // else // cb_Link_Colour.Items.Add(colour); // i++; // } // cb_Node_Colour.SelectedIndex = 0; // cb_Link_Colour.SelectedIndex = 0; // 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(); // Cube cb = new Cube(); // foreach (var item in cb.FacesVertices) // { // AreaViewModel area = new AreaViewModel(); // area.ID = item.Key.ToString(); // area.InnerNodes = new List(); // //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[] { CubeViewMouseDown, CubeViewMouseMove, CubeViewMouseUp, mapMouseWheel }); // } // #endregion // #region 对外开放,全局控制方法 // public bool LoadData(bool isDelCache = false) // { // if (_Template == null) return false; // if (isDelCache || _Template.network == null) // { // if (!_Template.loadInpFile()) // { // _Template.network = new MapViewNetWork(); // //return false; // } // } // SuspendLayout(); // if (_ViewModel == null) // { // if (!_IsEditMode) // { // if (param == null) // param = new dict(); // _Template.network.LoadRepeaters(_Template.MaxLevel, param, _ViewModel, !_IsEditMode); // } // else // { // if (param == null) // param = new dict(); // _Template.network.LoadRepeaters(_Template.MaxLevel, param, null, !_IsEditMode); // } // } // else // { // if (_IsEditMode) // { // if (param == null) // param = new dict(); // _Template.network.LoadRepeaters(_Template.MaxLevel, param, _ViewModel, !_IsEditMode); // } // else // { // if (param == null) // param = new dict(); // _Template.network.LoadRepeaters(_Template.MaxLevel, param, null, !_IsEditMode); // } // } // if (GlobalObject.PropertyForm != null) // { // GlobalObject.PropertyForm.SetEnabled(_IsEditMode); // GlobalObject.PropertyForm.SetNet(_Template.network); // } // SetStartEndPoint(_Template.Node1, _Template.Node2); // ResumeLayout(false); // return true; // } // Dictionary _ViewModel = null; // public void Clear() // { // _Template = null; // MapCenter = PointF.Empty; // zoom = 1.0f; // Rotation = 0; // RotationF = 90; // SetMapInvalidate(); // } // public void SetData(Template template, dict param = null, Dictionary viewMode = null) // { // this.param = param; // bool reLoad = _Template == template; // this._Template = template; // this._ViewModel = viewMode; // if (!LoadData()) return; // if (!reLoad) // { // if (_Template.view == null) // InitCenter(); // else // { // this.mapOption = _Template.view.Copy(); // SetMapInvalidate(); // } // } // 刷新楼层ToolStripMenuItem_Click(1, new EventArgs()); // 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")})"; // } // private void InitCenter() // { // var p = PointF.Empty; // float x0 = 99999999999f, y0 = 99999999999f, x1 = -99999999999f, y1 = -99999999999f; // foreach (NodeViewModel junction in _Nodes) // { // p.X += (float)junction.X; // p.Y += (float)junction.Y; // if (x0 > junction.X) x0 = junction.X; // if (y0 > junction.Y) y0 = junction.Y; // if (x1 < junction.X) x1 = junction.X; // if (y1 < junction.Y) y1 = junction.Y; // } // float x_span = x1 - x0, y_span = y1 - y0; // zoom = Math.Min(this.map.Width / x_span, this.map.Height / y_span); // zoom = Math.Max(zoom, MinZoom); // zoom = Math.Min(zoom, MaxZoom); // Rotation = 0; // RotationF = 90; // if (_Nodes.Count > 0) // { // p.X /= _Nodes.Count; // p.Y /= _Nodes.Count; // } // MapCenter = p; // } // public void SetMapInvalidate() // { // _needPaintAll = true; // PMin_Show = ScreenToMap(new PointF(0, this.map.Height)); // PMax_Show = ScreenToMap(new PointF(this.map.Width, 0)); // _timerDraw = true; // } // public void SetStartEndPoint(String node1, string node2) // { // _StartPoint = node1; // _EndPoint = node2; // SetMapInvalidate(); // } // public void Set3DView(bool is3Dview, double 俯视角度) // { // this.RotationF = 俯视角度; // this.is3Dview = is3Dview; // SetMapInvalidate(); // } // public void SetRotation(double d) // { // this.Rotation = d; // SetMapInvalidate(); // } // #endregion // #region 重绘函数 // bool _needPaintAll // { // get // { // return __needpaintall; // } // set // { // __needpaintall = value; // } // } // PointF[] getCurclePoints(int num) // { // PointF[] points = new PointF[num + 1]; // float angle = 0; // for (int i = 0; i < points.Length; i++) // { // float x = (float)Math.Cos(angle); // float y = (float)Math.Sin(angle); // points[i] = new PointF(x, y); // angle += 2 * (float)Math.PI / num; // } // points[num] = points[0]; // return points; // } // private void timer_draw_Tick(object sender, EventArgs e) // { // _mouseHoverCheckFlag = true; // if (_timerDraw && map.Status == DrawingStatus.Ready) // { // this.map.Invalidate(); // this.CubeView.Invalidate(); // _timerDraw = false; // } // } // protected override void OnResize(EventArgs e) // { // base.OnResize(e); // this.SetMapInvalidate(); // } // #endregion // #region 鼠标事件 // void mapMouseDown(MouseEventArgs e) // { // base.OnMouseDown(e); // _ClickStartPos = new PointF(e.X, e.Y); // DragStartPos = ScreenToMap(new PointF(e.X, e.Y)); // mousePosition = _MousePosition = ScreenToMap(new PointF(e.X, e.Y)); // if (e.Button == MouseButtons.Left && _isInsertingObject) // { // } // else // if (e.Button == MouseButtons.Middle || e.Button == MouseButtons.XButton2) // { // if (ModifierKeys == Keys.Control || ModifierKeys == Keys.Shift) // { // DragStartPos = ScreenToMap(new PointF(e.X, e.Y)); // _isDragging = true; // } // else // { // _lastCursor = this.Cursor; // this.Cursor = Cursors.SizeAll; // MapCenter0 = MapCenter; // mapOption0 = mapOption.Copy(); // _isPanning = true; // } // } // else if (e.Button == MouseButtons.Left && _mouseState == MouseState.无) // { // if (ModifierKeys == Keys.Shift) // { // var point = ScreenToMap(new PointF(e.X, e.Y)); // if (!_isDrawingPolygon) // { // polygonPoints.Clear(); // _isDrawingPolygon = true; // } // polygonPoints.Add(point); // mousePosition = _MousePosition = ScreenToMap(new PointF(e.X, e.Y)); // SetMapInvalidate(); // return; // } // if (_isDrawingPolygon) // { // return; // } // //移动 // if (_IsEditMode && selectedObjs.Count >= 1) // { // List nodes = selectedNodes; // foreach (NodeViewModel node in nodes) // { // PointF mapPos = WorldPointToMapPoint(node); // PointF currentPoint = MapToScreen(mapPos); // if (Get_dist(new PointF(e.X, e.Y), currentPoint) < 15f) // { // _NewNet.Nodes.AddRange(selectedNodes); // _NewNet.Links.AddRange(selectedLinks); // _isMovingObject = true; // _OperaNode = node; // _undoOldValue = node.Position3D; // break; // } // } // } // if (!_isMovingObject)//拖拽选择 // { // DragStartPos = ScreenToMap(new PointF(e.X, e.Y)); // _isDragging = true; // } // } // else if (e.Button == MouseButtons.Left && _mouseState == MouseState.设置底图范围) // { // _mouseState = MouseState.无; // DragStartPos = ScreenToMap(new PointF(e.X, e.Y)); // BackGroudPicLeftPos = MapPointToWorldPoint(ScreenToMap(new PointF(e.X, e.Y)), _Template.BackGroundElev); // _isSettingBackGroundPictur = true; // } // else if (e.Button == MouseButtons.Right) // { // RotaStartPos = new PointF(e.X, e.Y); // Rotation0 = Rotation; // 俯视角度_start = RotationF; // _lastCursor = this.Cursor; // Cursor = Cursors.Hand; // mapOption0 = mapOption.Copy(); // _isRotating = true; // } // } // private bool IsPointInPolygon(PointF point, List polygon) // { // int count = polygon.Count; // bool inside = false; // PointF p1, p2; // for (int i = 0, j = count - 1; i < count; j = i++) // { // p1 = polygon[i]; // p2 = polygon[j]; // if (((p1.Y > point.Y) != (p2.Y > point.Y)) && // (point.X < (p2.X - p1.X) * (point.Y - p1.Y) / (p2.Y - p1.Y) + p1.X)) // { // inside = !inside; // } // } // return inside; // } // public void InsertNet(Template temp) // { // _isInsertingObject = true; // _newTemplate = temp; // _undoOldValue = new PointF3D(0, 0, 0); // _OperaNode = temp.network.Nodes.Find(node => node.ID == temp.Node1); // } // bool controlDown = false; // PointF _MousePosition = new PointF(0, 0); // void mapMouseMove(MouseEventArgs e) // { // //base.OnMouseMove(e); // bool needInvalidate = false; // _MousePosition = ScreenToMap(new PointF(e.X, e.Y)); // if (_isMovingObject) // { // var p = MapPointToWorldPoint(_MousePosition, _OperaNode.Elev); // var oldP = (PointF3D)_undoOldValue; // if (!float.IsInfinity(p.X) && !float.IsInfinity(p.Y)) _newTemplate.OffSet = new PointF3D(p.X - oldP.X, p.Y - oldP.Y, 0); //_OperaNode.Position = p; // GlobalObject.PropertyForm.propertyGrid.Refresh(); // needInvalidate = true; // } // else if (_isPainting) // { // needInvalidate = true; // } // else if (_isPanning) // { // var vector = GetRotateVector(new PointF(e.X, e.Y), new PointF(_lastMouseX, _lastMouseY)); // MapCenter = new PointF(MapCenter.X - vector.X / Zoom.X, MapCenter.Y - vector.Y / Zoom.Y); // label_center.Text = $"center:({MapCenter.X.ToString("0.000")} ,{MapCenter.Y.ToString("0.000")})"; // needInvalidate = true; // } // else if (_isDragging || _isDrawingPolygon || _isSettingBackGroundPictur) // { // mousePosition = _MousePosition; // needInvalidate = true; // } // else if (_isRotating) // { // mousePosition = _MousePosition; // bool is下半屏幕 = RotaStartPos.Y >= this.map.Height / 2; // if (ModifierKeys != Keys.Alt) Rotation = Rotation0 + ((float)e.X - (float)RotaStartPos.X) * 180 * 2.5 / (float)this.map.Width * (is下半屏幕 ? 1 : 1); // if (ModifierKeys != Keys.Shift) RotationF = 俯视角度_start + ((float)e.Y - (float)RotaStartPos.Y) * 180 * 2.5 / (float)this.map.Height; // if (RotationF > 90) RotationF = 90; // if (RotationF < 0) RotationF = 0; // needInvalidate = true; // } // else // if (_isInsertingObject) // { // var p = MapPointToWorldPoint(_MousePosition, _OperaNode.Elev); // var oldP = (PointF3D)_undoOldValue; // if (!float.IsInfinity(p.X) && !float.IsInfinity(p.Y)) _newTemplate.OffSet = new PointF3D(p.X - oldP.X, p.Y - oldP.Y, 0); //_OperaNode.Position = p; // GlobalObject.PropertyForm.propertyGrid.Refresh(); // needInvalidate = true; // } // /*判断是否触碰到对象*/ // if (_mouseHoverCheckFlag) // { // _mouseHoverCheckFlag = false; // // 遍历所有对象,找出范围内的对象 // PointF clickedPoint = new PointF(e.X, e.Y); // var obj = GetObj_by_ScreenPoint(clickedPoint); // if (hoveredObjs.Count > 0 && hoveredObjs[0] == obj || hoveredObjs.Count == 0 && obj == null) // { // } // else // { // needInvalidate = true; // hoveredObjs.ForEach(o => o.Hovered = false); // hoveredObjs.Clear(); // if (obj != null) // { // obj.Hovered = true; // hoveredObjs.Add(obj); // } // } // } // if (needInvalidate) this.SetMapInvalidate(); // label_mouse.Text = $"X:{e.X.ToString("0")} Y:{e.Y.ToString("0")} [Map]X:{_MousePosition.X.ToString("0.00")} Y:{_MousePosition.Y.ToString("0.00")}"; // _lastMouseX = e.X; // _lastMouseY = e.Y; // } // bool RectangContain(RectangleF r, PointF p) // { // var x = p.X; var y = p.Y; // if (r.X <= x && x < r.X + r.Width && r.Y <= y) // { // return y < r.Y + r.Height; // } // return false; // } // /// 用于绘制管线 // NodeViewModel _select_junction1 = null; // NodeViewModel _select_junction2 = null; // DateTime _lastMouseUp = DateTime.Now; // int doubleClick_Delay = 500;//毫秒 // bool recordView = false; // void mapMouseUp(MouseEventArgs e) // { // //BookMark:鼠标抬起事件 // base.OnMouseUp(e); // bool isMouseMoved = Get_dist(_ClickStartPos, new PointF(e.X, e.Y)) > 10; // bool isdoubleClick = (DateTime.Now - _lastMouseUp).TotalMilliseconds <= doubleClick_Delay; // _lastMouseUp = DateTime.Now; // if /*框选放大*/(ModifierKeys == Keys.Control && (e.Button == MouseButtons.Middle || e.Button == MouseButtons.XButton2)) // { // _isDragging = false; // this.Cursor = _lastCursor; // mapOption0 = mapOption; // var _lastMousePosition = DragStartPos; // List objs = new List(); // // 绘制矩形 // var start = new Point((int)Math.Min(mousePosition.X, _lastMousePosition.X), (int)Math.Min(mousePosition.Y, _lastMousePosition.Y)); // var size = new Size((int)Math.Abs(_lastMousePosition.X - mousePosition.X), (int)Math.Abs(_lastMousePosition.Y - mousePosition.Y)); // var rectangle0 = new Rectangle(start, size); // var new_center = MapPointToWorldPoint(new PointF(start.X + size.Width / 2, start.Y + size.Height / 2)); // this.MapCenter = new_center; // this.zoom = Math.Max(1.0f * this.map.Width / size.Width, 1.0f * this.map.Height / size.Height); // if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); // label_center.Text = $"center:({MapCenter.X.ToString("0.000")} ,{MapCenter.Y.ToString("0.000")})"; // label_zoom.Text = $"Zoom:{zoom.ToString("0.000")}"; // SetMapInvalidate(); // return; // } // if /*放大镜*/(ModifierKeys == Keys.Shift && (e.Button == MouseButtons.Middle || e.Button == MouseButtons.XButton2)) // { // _isDragging = false; // this.Cursor = _lastCursor; // var _lastMousePosition = DragStartPos; // List objs = new List(); // // 绘制矩形 // var start = new Point((int)Math.Min(mousePosition.X, _lastMousePosition.X), (int)Math.Min(mousePosition.Y, _lastMousePosition.Y)); // var size = new Size((int)Math.Abs(_lastMousePosition.X - mousePosition.X), (int)Math.Abs(_lastMousePosition.Y - mousePosition.Y)); // var rectangle0 = new Rectangle(start, size); // for (int i = 0; i < _Nodes.Count; i++) // { // var node = _Nodes[i] as NodeViewModel; // PointF p = WorldPointToMapPoint(node); // if (rectangle0.Contains(p.ToPoint())) // { // objs.Add(node); // } // } // for (int i = 0; i < _Links.Count; i++) // { // var link = _Links[i] as LinkViewModel; // if (rectangle0.Contains(link.Position.ToPoint())) // { // objs.Add(link); // } // } // return; // } // if /*平移视角*/(ModifierKeys == Keys.None && (e.Button == MouseButtons.Middle || e.Button == MouseButtons.XButton2)) // { // if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); // this.Cursor = _lastCursor; // _isPanning = false; // return; // } // if /*设置背景*/(e.Button == MouseButtons.Left && _isSettingBackGroundPictur) // { // _Template.BackGroundPoint1 = BackGroudPicLeftPos; // _Template.BackGroundPoint2 = MapPointToWorldPoint(mousePosition, _Template.BackGroundElev); // _isSettingBackGroundPictur = false; // mapOption.isShowPic = true; // this.Cursor = _lastCursor; // SetMapInvalidate(); // return; // } // if/*插入结构*/(e.Button == MouseButtons.Left && _isInsertingObject) // { // var net = _newTemplate.network;//clone // var net0 = _newTemplate.network.DeepCopy(); // List nodes = _Nodes.Select(node => (NodeViewModel)node).ToList(); // float minDist = 100f; // NodeViewModel minNode = null; // foreach (NodeViewModel node in nodes) // { // PointF mapPos = WorldPointToMapPoint(node); // PointF currentPoint = MapToScreen(mapPos); // float currentDist = 0; // if (node != _OperaNode && (currentDist = Get_dist(new PointF(e.X, e.Y), currentPoint)) < 15f) // { // if (currentDist < minDist) currentDist = minDist; // minNode = node; // break; // } // } // float dx, dy, dz; // if (ModifierKeys != Keys.Alt && minNode != null) // { // var p1 = (PointF3D)_undoOldValue; // var p2 = minNode.Position3D; // //var dd = _newTemplate.OffSet; // dx = p2.X - p1.X; // dy = p2.Y - p1.Y; // dz = p2.Z - p1.Z; // } // else // { // _NewNet.Clear(); // _OperaNode = null; // _isInsertingObject = false; // this.SetMapInvalidate(); // return; // } // 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(minNode, _OperaNode); // //j.Length = 0.0001f; // list.Add(j); // _OperaNode = null; // _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); // _isInsertingObject = false; // _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; // } // if/*多边形选择*/(_isDrawingPolygon && e.Button == MouseButtons.Left && ModifierKeys == Keys.None) // { // _isDrawingPolygon = false; // if (polygonPoints.Count >= 3) // { // _Nodes.ForEach(n0 => // { // var n = (NodeViewModel)n0; // if (IsPointInPolygon(WorldPointToMapPoint(n), polygonPoints)) // { // selectedObjs.Add(n); // n.Selected = true; // } // }); // _Links.ForEach(n0 => // { // var n = (LinkViewModel)n0; // if (IsPointInPolygon(WorldPointToMapPoint(n.Position, n.Elev), polygonPoints)) // { // selectedObjs.Add(n); // n.Selected = true; // } // }); // } // SetMapInvalidate(); // // 结束绘制多边形 // return; // } // if/*移动对象*/(_isMovingObject && isMouseMoved && e.Button == MouseButtons.Left) // { // List nodes = _Nodes.Select(n => (NodeViewModel)n).ToList(); // float minDist = 100f; // NodeViewModel minNode = null; // foreach (NodeViewModel node in nodes) // { // PointF mapPos = WorldPointToMapPoint(node); // PointF currentPoint = MapToScreen(mapPos); // float currentDist = 0; // if (node != _OperaNode && (currentDist = Get_dist(new PointF(e.X, e.Y), currentPoint)) < 15f) // { // if (currentDist < minDist) currentDist = minDist; // minNode = node; // break; // } // } // if (ModifierKeys != Keys.Alt && minNode != null) // { // _isMovingObject = false; // var p1 = (PointF3D)_undoOldValue; // var p2 = minNode.Position3D; // var dd = _newTemplate.OffSet; // var dx = p2.X - p1.X; // var dy = p2.Y - p1.Y; // var dz = p2.Z - p1.Z; // selectedNodes.ForEach(n => { n.Position3D = new PointF3D(n.X + dx, n.Y + dy, n.Elev + dz); }); // List newPositons = selectedNodes.Select(n => n.Position3D).ToList(); // List oldPositons = newPositons.Select(n => new PointF3D(n.X - dx, n.Y - dy, n.Z - dz)).ToList(); // MapObjectExtensions.AddCommand(selectedNodes, "Position3D", oldPositons, newPositons); // var l = new List(); // l.Add(_Network.AddPipe(_OperaNode, minNode)); // if (l.Count > 0) MapObjectExtensions.AddCommand(_Network, "Add", null, l); // _OperaNode = null; // _NewNet.Clear(); // } // else // { // _isMovingObject = false; // var p1 = (PointF3D)_undoOldValue; // var p2 = _OperaNode.Position3D; // var dd = _newTemplate.OffSet; // var dx = dd.X; //p2.X - p1.X; // var dy = dd.Y;// p2.Y - p1.Y; // var dz = dd.Z;// p2.Z - p1.Z; // selectedNodes.ForEach(n => { n.Position3D = new PointF3D(n.X + dx, n.Y + dy, n.Elev + dz); }); // List newPositons = selectedNodes.Select(n => n.Position3D).ToList(); // List oldPositons = newPositons.Select(n => new PointF3D(n.X - dx, n.Y - dy, n.Z - dz)).ToList(); // MapObjectExtensions.AddCommand(selectedNodes, "Position3D", oldPositons, newPositons); // _OperaNode = null; // _NewNet.Clear(); // } // this.SetMapInvalidate(); // return; // } // if/*取消移动对象*/(_isMovingObject && !isMouseMoved && e.Button == MouseButtons.Left) // { // _isMovingObject = false; // var p1 = (PointF3D)_undoOldValue; // var p2 = _OperaNode.Position3D; // var dd = _newTemplate.OffSet; // var dx = dd.X; //p2.X - p1.X; // var dy = dd.Y;// p2.Y - p1.Y; // var dz = dd.Z;// p2.Z - p1.Z; // //selectedNodes.ForEach(n => { n.Position3D = new PointF3D(n.X + dx, n.Y + dy, n.Elev + dz); }); // //List newPositons = selectedNodes.Select(n => n.Position3D).ToList(); // //List oldPositons = newPositons.Select(n => new PointF3D(n.X - dx, n.Y - dy, n.Z - dz)).ToList(); // //MapObjectExtensions.AddCommand(selectedNodes, "Position3D", oldPositons, newPositons); // _OperaNode = null; // _NewNet.Clear(); // return; // } // if /*特殊功能*/(_mouseState != MouseState.无 && e.Button == MouseButtons.Left) // { // PointF p; // float z; // NodeViewModel n; // switch (_mouseState) // { // case MouseState.新增节点: // getPointAndHeight(e, out p, out z); // n = _Network.AddJunction(p, z); // MapObjectExtensions.AddCommand(_Network, "Add", null, new List() { n }); // break; // case MouseState.新建水表: // getPointAndHeight(e, out p, out z); // n = _Network.AddMeter(p); // MapObjectExtensions.AddCommand(_Network, "Add", null, new List() { n }); // break; // case MouseState.新建水库: // getPointAndHeight(e, out p, out z); // n = _Network.AddReservoir(p); // MapObjectExtensions.AddCommand(_Network, "Add", null, new List() { n }); // break; // case MouseState.新建水池: // getPointAndHeight(e, out p, out z); // n = _Network.AddTank(p); // MapObjectExtensions.AddCommand(_Network, "Add", null, new List() { n }); // break; // case MouseState.新增管线: // case MouseState.新增立管: // case MouseState.新建水泵: // case MouseState.新建阀门: // case MouseState.新建重复器: // if (_select_junction1 == null) // { // if (_mouseState == MouseState.新增立管) // { // var m = ScreenToVMap(new PointF(e.X, e.Y)); // z = m.Y; // p = new PointF(m.X, 0); // Set_junction1(e); // } // else // { // getPointAndHeight(e, out p, out z); // Set_junction1(e); // } // } // else // { // if (_mouseState == MouseState.新增立管) // { // //需要把鼠标位置转换为立管的位置,获取鼠标位置的高程 // var wPos = GetZZWorldPoint(_select_junction1.Position3D, _MousePosition, new Vector3(0, 0, 1)); // //var m = ScreenToVMap(new PointF(e.X, e.Y)); // //z = m.Y; // p = new PointF(wPos.X, wPos.Y); // var l = AddLink(new PointF(e.X, e.Y), isdoubleClick, p, wPos.Z); // if (l.Count > 0) MapObjectExtensions.AddCommand(_Network, "Add", null, l); // } // else // { // if (mapOption.IsOrtho) // { // var wPos = GetZZWorldPoint(_select_junction1.Position3D, _MousePosition, new Vector3(1, 1, 0)); // //getPointAndHeight(e, _select_junction1, out p, out z); // p = new PointF(wPos.X, wPos.Y); // var l = AddLink(new PointF(e.X, e.Y), isdoubleClick, p, wPos.Z); // if (l.Count > 0) MapObjectExtensions.AddCommand(_Network, "Add", null, l); // } // else // { // getPointAndHeight(e, _select_junction1, out p, out z); // var l = AddLink(new PointF(e.X, e.Y), isdoubleClick, p, z); // if (l.Count > 0) MapObjectExtensions.AddCommand(_Network, "Add", null, l); // } // } // } // break; // } // _Network.BuildRelation(); // SetMapInvalidate(); // } // if /*锁定点选*/(GlobalObject.LockSelect && !isMouseMoved && _mouseState == MouseState.无 && e.Button == MouseButtons.Left) // { // _isDragging = false; // // 遍历所有点,找出最近的点 // PointF clickedPoint = new PointF(e.X, e.Y);//ScreenToMap(new PointF(e.X, e.Y)); // var obj = GetObj_by_ScreenPoint(clickedPoint); // bool isJunction = obj is NodeViewModel; // if (obj != null) // { // GlobalObject.PropertyForm.SetObjs(new List() { obj }); // if (isJunction) _OperaNode = (NodeViewModel)obj; // mousePosition = new PointF(0, 0); // SetMapInvalidate(); // } // else // { // GlobalObject.PropertyForm.SetObjs(new List() { }); // _OperaNode = null; // mousePosition = new PointF(0, 0); // SetMapInvalidate(); // } // return; // } // if /*锁定框选*/(GlobalObject.LockSelect && isMouseMoved && _mouseState == MouseState.无 && e.Button == MouseButtons.Left) // { // _isDragging = false; // Cursor = Cursors.Default; // 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); // var selectedObjs = new List(); // for (int i = 0; i < _Nodes.Count; i++) // { // var node = _Nodes[i] as NodeViewModel; // if (!node.Visible) continue; // PointF p = WorldPointToMapPoint(node); // if (RectangContain(rectangle0, p)) // { // selectedObjs.Add(node); // } // } // for (int i = 0; i < _Links.Count; i++) // { // var link = _Links[i] as LinkViewModel; // if (!link.Visible) continue; // PointF p = WorldPointToMapPoint(link.Position, link.Elev); // if (RectangContain(rectangle0, p)) // { // selectedObjs.Add(link); // } // } // var findNode = selectedObjs.FindAll(o => o is NodeViewModel); // if (findNode.Count > 0) _OperaNode = findNode[0] as NodeViewModel; // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // SetMapInvalidate(); // mousePosition = new PointF(0, 0); // return; // } // if /*叠加框选*/(isMouseMoved && _mouseState == MouseState.无 && e.Button == MouseButtons.Left && ModifierKeys == Keys.Control) // { // _isDragging = false; // Cursor = Cursors.Default; // 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); // for (int i = 0; i < _Nodes.Count; i++) // { // var node = _Nodes[i] as NodeViewModel; // if (!node.Visible) continue; // PointF p = WorldPointToMapPoint(node); // if (RectangContain(rectangle0, p)) // { // if (selectedObjs.Contains(node)) // { // node.Selected = false; // selectedObjs.Remove(node); // } // else // { // node.Selected = true; // selectedObjs.Add(node); // } // } // } // for (int i = 0; i < _Links.Count; i++) // { // var link = _Links[i] as LinkViewModel; // if (!link.Visible) continue; // PointF p = WorldPointToMapPoint(link.Position, link.Elev); // if (RectangContain(rectangle0, p)) // { // if (selectedObjs.Contains(link)) // { // link.Selected = false; // selectedObjs.Remove(link); // } // else // { // link.Selected = true; // selectedObjs.Add(link); // } // } // } // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // SetMapInvalidate(); // mousePosition = new PointF(0, 0); // return; // } // if /*框选*/(isMouseMoved && _mouseState == MouseState.无 && e.Button == MouseButtons.Left && ModifierKeys == Keys.None) // { // _isDragging = false; // Cursor = Cursors.Default; // 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); // selectedObjs.ForEach(obj => obj.Selected = false); // selectedObjs.Clear(); // for (int i = 0; i < _Nodes.Count; i++) // { // var node = _Nodes[i] as NodeViewModel; // if (!node.Visible) continue; // PointF p = WorldPointToMapPoint(node); // if (RectangContain(rectangle0, p)) // { // node.Selected = true; // selectedObjs.Add(node); // } // } // for (int i = 0; i < _Links.Count; i++) // { // var link = _Links[i] as LinkViewModel; // if (!link.Visible) continue; // PointF p = WorldPointToMapPoint(link.Position, link.Elev); // if (RectangContain(rectangle0, p)) // { // link.Selected = true; // selectedObjs.Add(link); // } // } // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // SetMapInvalidate(); // mousePosition = new PointF(0, 0); // return; // } // if /*点选*/(!isMouseMoved && _mouseState == MouseState.无 && e.Button == MouseButtons.Left && ModifierKeys == Keys.None) // { // _isDragging = false; // // 遍历所有点,找出最近的点 // PointF clickedPoint = new PointF(e.X, e.Y);//ScreenToMap(new PointF(e.X, e.Y)); // var obj = GetObj_by_ScreenPoint(clickedPoint); // bool isJunction = obj is NodeViewModel; // if (obj != null) // { // selectedObjs.ForEach(o => o.Selected = false); // selectedObjs.Clear(); // obj.Selected = true; // selectedObjs.Add(obj); // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // _OperaNode = null; // SetMapInvalidate(); // mousePosition = new PointF(0, 0); // } // else // { // //GlobalObject.LockSelect // selectedObjs.ForEach(o => o.Selected = false); // selectedObjs.Clear(); // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // _OperaNode = null; // SetMapInvalidate(); // } // return; // } // if (/*叠加点选*/!isMouseMoved && _mouseState == MouseState.无 && e.Button == MouseButtons.Left && ModifierKeys == Keys.Control) // { // _isDragging = false; // // 遍历所有点,找出最近的点 // PointF clickedPoint = new PointF(e.X, e.Y);//ScreenToMap(new PointF(e.X, e.Y)); // var obj = GetObj_by_ScreenPoint(clickedPoint); // bool isJunction = obj is NodeViewModel; // if (obj != null) // { // if (selectedObjs.Contains(obj)) // { // obj.Selected = false; // selectedObjs.Remove(obj); // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // SetMapInvalidate(); // mousePosition = new PointF(0, 0); // } // else // { // obj.Selected = true; // selectedObjs.Add(obj); // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // SetMapInvalidate(); // mousePosition = new PointF(0, 0); // } // } // return; // } // if (e.Button == MouseButtons.Right) // { // if (_isRotating) // { // _isRotating = false; // this.Cursor = _lastCursor; // if (!isMouseMoved) // { // 右键_Menu.Show(this, e.Location); // 转换为ToolStripMenuItem.Enabled = selectedNodes.Count > 0; //(selectedObjs.Count == 1); // 删除ToolStripMenuItem.Enabled = selectedObjs.Count > 0; // 删除ToolStripMenuItem1.Enabled = selectedObjs.Count > 0; // } // if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); // mousePosition = new PointF(0, 0); // } // } // } // private void getPointAndHeight(MouseEventArgs e, out PointF p, out float z) // { // z = 0; // if (RotationF != 0) // { // p = MapPointToWorldPoint(ScreenToMap(new PointF(e.X, e.Y), z)); // } // else // { // var m = ScreenToVMap(new PointF(e.X, e.Y)); // z = m.Y; // p = new PointF(m.X, 0); // } // } // private void getPointAndHeight(MouseEventArgs e, NodeViewModel j, out PointF p, out float z) // { // z = j.Elev; // if (RotationF != 0) // { // p = MapPointToWorldPoint(ScreenToMap(new PointF(e.X, e.Y), j.Elev), j.Elev); // } // else // { // var m = ScreenToVMap(new PointF(e.X, e.Y)); // z = m.Y; // p = new PointF(j.X, j.Y); // } // } // IBaseViewModel GetObj_by_ScreenPoint(PointF clickedPoint, float DistLimit = 15f) // { // float minDist = float.MaxValue; // int minIndex = -1; // bool isJunction = true; // IBaseViewModel obj = null; // for (int i = 0; i < _Nodes.Count; i++) // { // var node = _Nodes[i] as NodeViewModel; // if (!node.Visible) continue; // PointF mapPos = WorldPointToMapPoint(node); // PointF currentPoint = MapToScreen(mapPos); // float dist = Get_dist(clickedPoint, currentPoint); // if (dist < minDist && dist <= DistLimit) // { // minDist = dist; // minIndex = i; // obj = node; // } // } // for (int i = 0; i < _Links.Count; i++) // { // var link = _Links[i] as LinkViewModel; // if (!link.Visible) continue; // //float dist = (clickedPoint.X - Pipes[i].X) * (clickedPoint.X - Pipes[i].X) + // //(clickedPoint.Y - Pipes[i].Y) * (clickedPoint.Y - Pipes[i].Y); // PointF mapPos1 = WorldPointToMapPoint(link.StartNode.Position, link.StartNode.Elev); // PointF currentPoint1 = MapToScreen(mapPos1); // PointF mapPos2 = WorldPointToMapPoint(link.EndNode.Position, link.EndNode.Elev); // PointF currentPoint2 = MapToScreen(mapPos2); // //根据currentPoint1和currentPoint2,判断clickedPoint离线段currentPoint1和currentPoint2的距离 // float dist = Get_dist(clickedPoint, currentPoint1, currentPoint2, DistLimit); // //float dist = Get_dist(clickedPoint, currentPoint); // if (dist < minDist && dist <= DistLimit) // { // minDist = dist; // minIndex = i; // isJunction = false; // obj = link; // } // } // return obj; // } // /// 鼠标滚轮事件 // void mapMouseWheel(MouseEventArgs e) // { // base.OnMouseWheel(e); // mapOption0 = mapOption.Copy(); // float oldZoom = zoom; // zoom *= (float)Math.Pow(2, e.Delta / 120.0 / 10.0); // zoom = Math.Max(MinZoom, Math.Min(MaxZoom, zoom)); // if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); // SetMapInvalidate(); // } // private int _lastMouseX; // private int _lastMouseY; // #endregion // #region CubeView鼠标事件 // void CubeViewMouseDown(MouseEventArgs e) // { // base.OnMouseDown(e); // _ClickStartPos = new PointF(e.X, e.Y); // DragStartPos = ScreenToMap(new PointF(e.X, e.Y)); // mousePosition = _MousePosition = ScreenToMap(new PointF(e.X, e.Y)); // if (e.Button == MouseButtons.Left && _isInsertingObject) // { // } // else if (e.Button == MouseButtons.Left && _mouseState == MouseState.无) // { // } // else if (e.Button == MouseButtons.Left && _mouseState == MouseState.设置底图范围) // { // } // else if (e.Button == MouseButtons.Right) // { // RotaStartPos = new PointF(e.X, e.Y); // Rotation0 = Rotation; // 俯视角度_start = RotationF; // _lastCursor = this.Cursor; // Cursor = Cursors.Hand; // mapOption0 = mapOption.Copy(); // _isRotating = true; // } // } // void CubeViewMouseMove(MouseEventArgs e) // { // //base.OnMouseMove(e); // bool needInvalidate = false; // _MousePosition = ScreenToMap(new PointF(e.X, e.Y)); // if (_isRotating) // { // mousePosition = _MousePosition; // bool is下半屏幕 = RotaStartPos.Y >= this.map.Height / 2; // if (ModifierKeys != Keys.Alt) Rotation = Rotation0 + ((float)e.X - (float)RotaStartPos.X) * 180 * 2.5 / (float)this.map.Width * (is下半屏幕 ? 1 : 1); // if (ModifierKeys != Keys.Shift) RotationF = 俯视角度_start + ((float)e.Y - (float)RotaStartPos.Y) * 180 * 2.5 / (float)this.map.Height; // if (RotationF > 90) RotationF = 90; // if (RotationF < 0) RotationF = 0; // needInvalidate = true; // } // //else // /*判断是否触碰到对象*/ // if (_mouseHoverCheckFlag) // { // _mouseHoverCheckFlag = false; // // 遍历所有对象,找出范围内的对象 // PointF clickedPoint = new PointF(e.X, e.Y);//ScreenToMap(new PointF(e.X, e.Y)); // var obj = GetObj_by_ScreenPoint(clickedPoint); // if (hoveredObjs.Count > 0 && hoveredObjs[0] == obj || hoveredObjs.Count == 0 && obj == null) // { // //needInvalidate = false; // } // else // { // needInvalidate = true; // hoveredObjs.ForEach(o => o.Hovered = false); // hoveredObjs.Clear(); // if (obj != null) // { // obj.Hovered = true; // hoveredObjs.Add(obj); // } // } // } // if (needInvalidate) this.SetMapInvalidate(); // label_mouse.Text = $"X:{e.X.ToString("0")} Y:{e.Y.ToString("0")} [Map]X:{_MousePosition.X.ToString("0.00")} Y:{_MousePosition.Y.ToString("0.00")}"; // _lastMouseX = e.X; // _lastMouseY = e.Y; // } // void CubeViewMouseUp(MouseEventArgs e) // { // //BookMark:鼠标抬起事件 // base.OnMouseUp(e); // bool isMouseMoved = Get_dist(_ClickStartPos, new PointF(e.X, e.Y)) > 10; // bool isdoubleClick = (DateTime.Now - _lastMouseUp).TotalMilliseconds <= doubleClick_Delay; // _lastMouseUp = DateTime.Now; // if /*点选*/(!isMouseMoved && _mouseState == MouseState.无 && e.Button == MouseButtons.Left && ModifierKeys == Keys.None) // { // _isDragging = false; // // 遍历所有点,找出最近的点 // PointF clickedPoint = new PointF(e.X, e.Y);//ScreenToMap(new PointF(e.X, e.Y)); // var obj = GetObj_by_ScreenPoint(clickedPoint); // bool isJunction = obj is NodeViewModel; // if (obj != null) // { // selectedObjs.ForEach(o => o.Selected = false); // selectedObjs.Clear(); // obj.Selected = true; // selectedObjs.Add(obj); // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // _OperaNode = null; // SetMapInvalidate(); // mousePosition = new PointF(0, 0); // } // else // { // //GlobalObject.LockSelect // selectedObjs.ForEach(o => o.Selected = false); // selectedObjs.Clear(); // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // _OperaNode = null; // SetMapInvalidate(); // } // return; // } // if (/*叠加点选*/!isMouseMoved && _mouseState == MouseState.无 && e.Button == MouseButtons.Left && ModifierKeys == Keys.Control) // { // _isDragging = false; // // 遍历所有点,找出最近的点 // PointF clickedPoint = new PointF(e.X, e.Y);//ScreenToMap(new PointF(e.X, e.Y)); // var obj = GetObj_by_ScreenPoint(clickedPoint); // bool isJunction = obj is NodeViewModel; // if (obj != null) // { // if (selectedObjs.Contains(obj)) // { // obj.Selected = false; // selectedObjs.Remove(obj); // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // SetMapInvalidate(); // mousePosition = new PointF(0, 0); // } // else // { // obj.Selected = true; // selectedObjs.Add(obj); // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // SetMapInvalidate(); // mousePosition = new PointF(0, 0); // } // } // return; // } // if (e.Button == MouseButtons.Right) // { // if (_isRotating) // { // _isRotating = false; // this.Cursor = _lastCursor; // if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); // mousePosition = new PointF(0, 0); // } // } // } // #endregion // #endregion 一、全局 // #region 二、工具栏 // #region 视角工具 // // 显示点属性 // private void ShowProperties(IBaseViewModel obj) // { // string str = "point"; // if (obj is LinkViewModel) str = "pipe"; // //MessageBox.Show($"{str}:({obj.X.ToString("0.000")} ,{obj.Y.ToString("0.000")})"); // //label_choose.Text = $"{str}[{obj.ID}]({obj.X.ToString("0.000")},{obj.Y.ToString("0.000")})"; // GlobalObject.PropertyForm.SetObj(obj); // } // private void label_center_Click(object sender, EventArgs e) // { // GlobalObject.PropertyForm.SetObj(MapCenter); // } // double 俯视角度_bak = 45; // private void tool视角_ButtonClick(object sender, EventArgs e) // { // mapOption0 = mapOption.Copy(); // if (RotationF == 90) // { // RotationF = 俯视角度_bak; // } // else // { // 俯视角度_bak = RotationF; // RotationF = 90; // } // if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); // SetMapInvalidate(); // } // private void tool设置俯视角度_Click(object sender, EventArgs e) // { // mapOption0 = mapOption.Copy(); // double jiaodu = 45; // var tool = sender as ToolStripItem; // jiaodu = Convert.ToDouble(tool.Text); // RotationF = jiaodu; // if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); // SetMapInvalidate(); // } // public void 重置视角ToolStripMenuItem_Click(object sender, EventArgs e) // { // mapOption0 = mapOption.Copy(); // RotationF = 90; // Rotation = 0; // InitCenter(); // if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); // SetMapInvalidate(); // } // private void 正视图ToolStripMenuItem_Click(object sender, EventArgs e) // { // mapOption0 = mapOption.Copy(); // RotationF = 0; // if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); // SetMapInvalidate(); // } // private void 俯视图ToolStripMenuItem_Click(object sender, EventArgs e) // { // mapOption0 = mapOption.Copy(); // RotationF = 90; // MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); // SetMapInvalidate(); // } // private void 默认视角ToolStripMenuItem_Click(object sender, EventArgs e) // { // mapOption0 = mapOption.Copy(); // InitCenter(); // RotationF = 45; // Rotation = -45; // MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); // SetMapInvalidate(); // } // private void 设为隐藏ToolStripMenuItem_Click(object sender, EventArgs e) // { // selectedObjs.ForEach(v => // { // if (v.Visible) // { // MapObjectExtensions.AddCommand(v, "Visible", v.Visible, false); // v.Visible = false; // } // }); // this.SetMapInvalidate(); // } // private void 设置长度ToolStripMenuItem_Click(object sender, EventArgs e) // { // double length = 0; // InputBox input = new InputBox("输入长度"); // if (selectedObjs.Count == 1 && selectedObjs[0] is LinkViewModel l) // { // if (double.TryParse(input.ShowDialog(), out length)) // { // var count1 = _Links.FindAll(ll => ll.Node1 == l.StartNode.ID || ll.Node2 == l.StartNode.ID).Count; // var count2 = _Links.FindAll(ll => ll.Node1 == l.EndNode.ID || ll.Node2 == l.EndNode.ID).Count; // if (count1 > 1 && count2 <= 1) // { // MovePointbyLength(l.StartNode, l.EndNode, (float)length); // } // else if (count2 > 1 && count1 <= 1) // { // MovePointbyLength(l.EndNode, l.StartNode, (float)length); // } // else // { // MovePointbyLength(l.StartNode, l.EndNode, (float)length); // } // SetMapInvalidate(); // } // } // this.SetMapInvalidate(); // } // void MovePointbyLength(NodeViewModel node1, NodeViewModel node2, float Length) // { // float distance = Vector3.Distance(new Vector3(node1.X, node1.Y, node1.Elev), new Vector3(node2.X, node2.Y, node2.Elev)); // if (distance > 0) // {// 如果 A 和 B 不是同一个点 // // 计算要移动多少距离 // float moveDistance = Length - distance; // // 计算向量 AB(从 A 指向 B) // Vector3 AB = new Vector3(node2.X - node1.X, node2.Y - node1.Y, node2.Elev - node1.Elev); // // 计算 AB 的单位向量 // Vector3 unitAB = Vector3.Normalize(AB); // // 计算需要移动的距离的向量(与 AB 方向相同) // Vector3 moveVector = unitAB * moveDistance; // // 更新点 B 的坐标 // node2.X += moveVector.X; // node2.Y += moveVector.Y; // node2.Elev += moveVector.Z; // } // } // private void 全部显示ToolStripMenuItem_Click(object sender, EventArgs e) // { // _Nodes.Select(n => (NodeViewModel)n).ToList().ForEach(v => // { // if (!v.Visible) // { // MapObjectExtensions.AddCommand(v, "Visible", v.Visible, true); // v.Visible = true; // } // }); // _Links.Select(n => (LinkViewModel)n).ToList().ForEach(v0 => // { // var v = (LinkViewModel)v0; // if (!v.Visible) // { // MapObjectExtensions.AddCommand(v, "Visible", v.Visible, true); // v.Visible = true; // } // }); // this.SetMapInvalidate(); // } // #endregion // #region 文件工具 // private void tool打开_ButtonClick(object sender, EventArgs e) // { // // 创建打开文件对话框 // OpenFileDialog openFileDialog = new OpenFileDialog(); // openFileDialog.Filter = "INP Files (*.inp)|*.inp|All Files (*.*)|*.*"; // if (openFileDialog.ShowDialog() == DialogResult.OK) // { // _Template = new Template(); // _Template.network = new MapViewNetWork(); // // 获取选中文件的文件路径 // string filePath = openFileDialog.FileName; // { // // 读取文件内容 // _Network.BuildFromInp(filePath); // _Template.filePath = filePath; // //_filePath = filePath; // SetData(_Template); // } // } // } // private void 旧版打开ToolStripMenuItem_Click(object sender, EventArgs e) // { // // 创建打开文件对话框 // OpenFileDialog openFileDialog = new OpenFileDialog(); // openFileDialog.Filter = "INP Files (*.inp)|*.inp|All Files (*.*)|*.*"; // if (openFileDialog.ShowDialog() == DialogResult.OK) // { // _Template = new Template(); // _Template.network = new MapViewNetWork(); // // 获取选中文件的文件路径 // string filePath = openFileDialog.FileName; // { // // 读取文件内容 // _Network.BuildFromInp(filePath); // _Template.filePath = filePath; // SetData(_Template); // } // } // } // private void 打开文件位置ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (_filePath == null) return; // FileInfo fi = new FileInfo(_filePath); // System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{_filePath}\""); // } // private void EPA中打开ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (_filePath == null) return; // System.Diagnostics.Process.Start(@"epanetH\Epanet2wH.exe", _filePath); // } // #endregion // #region 绘图工具 // public void toolStripButton_新建节点_Click(object sender, EventArgs e) // { // _mouseState = MouseState.新增节点; // Cursor = Cursors.Cross; // } // public void toolStripButton_普通_Click(object sender, EventArgs e) // { // _mouseState = MouseState.无; // Cursor = Cursors.Default; // if (_isPainting) // { // _select_junction1 = null; // _isPainting = false; // SetMapInvalidate(); // } // else if (_isDragging) // { // _isDragging = false; // SetMapInvalidate(); // } // else if (_isPanning) // { // _isPanning = false; // SetMapInvalidate(); // } // else if (_isRotating) // { // Rotation = Rotation0; // _isRotating = false; // SetMapInvalidate(); // } // else if (_isMovingObject) // { // _NewNet.Clear(); // _isMovingObject = false; // SetMapInvalidate(); // } // else if (_mouseState != MouseState.无) // { // _mouseState = MouseState.无; // Cursor = Cursors.Default; // } // else if (_isInsertingObject) // { // _NewNet.Clear(); // _isInsertingObject = false; // _OperaNode = null; // SetMapInvalidate(); // } // else // { // _Nodes.ForEach(o => ((NodeViewModel)o).Selected = false); // _Links.ForEach(o => ((LinkViewModel)o).Selected = false); // selectedObjs.Clear(); // SetMapInvalidate(); // } // } // public void toolStripButton_新建管线_Click(object sender, EventArgs e) // { // _mouseState = MouseState.新增管线; // Cursor = Cursors.Cross; // } // public void toolStripButton_新建立管_Click(object sender, EventArgs e) // { // _mouseState = MouseState.新增立管; // Cursor = Cursors.Cross; // } // private List AddLink(PointF e, bool isdoubleClick, PointF p, float z) // { // List l = new List(); // var node = GetObj_by_ScreenPoint(e); // if (node != null || isdoubleClick) // { // if (node != null && node is NodeViewModel j) // { // _select_junction2 = j; // } // else if (isdoubleClick) // { // _select_junction2 = _Network.AddJunction(p, z); // l.Add(_select_junction2); // } // if (_mouseState == MouseState.新增管线 || _mouseState == MouseState.新增立管) // l.Add(_Network.AddPipe(_select_junction1, _select_junction2)); // else if (_mouseState == MouseState.新建阀门) // l.Add(_Network.AddValve(_select_junction1, _select_junction2)); // else if (_mouseState == MouseState.新建重复器) // l.Add(_Network.AddRepeater(_select_junction1, _select_junction2)); // else if (_mouseState == MouseState.新建水泵) // l.Add(_Network.AddPump(_select_junction1, _select_junction2)); // _select_junction1 = null; // _select_junction2 = null; // _isPainting = false; // } // return l; // } // private void Set_junction1(MouseEventArgs e) // { // var node = GetObj_by_ScreenPoint(new PointF(e.X, e.Y)); // if (node != null && node is NodeViewModel j) // { // _select_junction1 = j; // _isPainting = true; // } // } // public void toolStripButton_添加水表_Click(object sender, EventArgs e) // { // _mouseState = MouseState.新建水表; // Cursor = Cursors.Cross; // } // public void toolStripButton_添加阀门_Click(object sender, EventArgs e) // { // _mouseState = MouseState.新建阀门; // Cursor = Cursors.Cross; // } // public void toolStripButton_添加水泵_Click(object sender, EventArgs e) // { // _mouseState = MouseState.新建水泵; // Cursor = Cursors.Cross; // } // public void toolStripButton_添加水库_Click(object sender, EventArgs e) // { // _mouseState = MouseState.新建水库; // Cursor = Cursors.Cross; // } // public void toolStripButton_添加水池_Click(object sender, EventArgs e) // { // _mouseState = MouseState.新建水池; // Cursor = Cursors.Cross; // } // public void toolStripButton_重复器_Click(object sender, EventArgs e) // { // _mouseState = MouseState.新建重复器; // Cursor = Cursors.Cross; // } // bool Buzylock = false; // public void MapViewer_KeyDown(object sender, KeyEventArgs e) // { // if (e.KeyCode == Keys.Escape) // { // Cursor = _lastCursor; // if (_isPainting) // { // _select_junction1 = null; // _isPainting = false; // SetMapInvalidate(); // } // else if (_isDragging) // { // _isDragging = false; // SetMapInvalidate(); // } // else if (_isPanning) // { // _isPanning = false; // SetMapInvalidate(); // } // else if (_isRotating) // { // Rotation = Rotation0; // _isRotating = false; // SetMapInvalidate(); // } // else if (_isMovingObject) // { // _NewNet.Clear(); // _isMovingObject = false; // SetMapInvalidate(); // } // else if (_mouseState != MouseState.无) // { // _mouseState = MouseState.无; // Cursor = Cursors.Default; // } // else if (_isInsertingObject) // { // _NewNet.Clear(); // _isInsertingObject = false; // _OperaNode = null; // SetMapInvalidate(); // } // else // { // _Nodes.ForEach(o => ((NodeViewModel)o).Selected = false); // _Links.ForEach(o => ((LinkViewModel)o).Selected = false); // selectedObjs.Clear(); // SetMapInvalidate(); // } // } // if (_IsEditMode && e.KeyCode == Keys.Delete) // { // DeleteChoosedObj(); // } // if (e.KeyCode == Keys.A && e.Modifiers == Keys.Control) // { // selectedObjs.Clear(); // _Nodes.ForEach(o => { ((NodeViewModel)o).Selected = true; selectedObjs.Add((NodeViewModel)o); }); // _Links.ForEach(o => { ((LinkViewModel)o).Selected = true; selectedObjs.Add((LinkViewModel)o); }); // SetMapInvalidate(); // } // if (_IsEditMode && e.KeyCode == Keys.C && e.Modifiers == Keys.Control) // { // 复制ToolStripMenuItem_Click(1, new EventArgs()); // } // if (_IsEditMode && e.KeyCode == Keys.V && e.Modifiers == Keys.Control) // { // _ClickStartPos = Cursor.Position; // 粘贴ToolStripMenuItem1_Click(1, new EventArgs()); // } // if (_IsEditMode && e.KeyCode == Keys.D1 && e.Modifiers == Keys.Control) // { // 南北对齐ToolStripMenuItem_Click(1, new EventArgs()); // } // if (_IsEditMode && e.KeyCode == Keys.Oemtilde && e.Modifiers == Keys.Control) // { // 东西对齐ToolStripMenuItem_Click(1, new EventArgs()); // } // if (_IsEditMode && e.KeyCode == Keys.D2 && e.Modifiers == Keys.Control) // { // 竖直对齐ToolStripMenuItem_Click(1, new EventArgs()); // } // if (_IsEditMode && e.KeyCode == Keys.D3 && e.Modifiers == Keys.Control) // { // 自动对齐ToolStripMenuItem_Click(1, new EventArgs()); // } // } // private void MapViewer_KeyPress(object sender, KeyPressEventArgs e) // { // if (_IsEditMode && ctrlPressed && e.KeyChar == 'Z' - 64) // { // // 执行相应的操作 // buttonUndo_Click(sender, e); // ctrlPressed = false; // // 防止默认操作 // e.Handled = true; // } // if (_IsEditMode && ctrlPressed && e.KeyChar == 'Y' - 64) // { // // 执行相应的操作 // buttonRedo_Click(sender, e); // ctrlPressed = false; // // 防止默认操作 // e.Handled = true; // } // if (ctrlPressed && e.KeyChar == 'R' - 64) // { // // 执行相应的操作 // tool视角_ButtonClick(sender, e); // ctrlPressed = false; // // 防止默认操作 // e.Handled = true; // } // } // private void MapViewer_PreKeyPress(object sender, PreviewKeyDownEventArgs e) // { // if (_IsEditMode && e.Control && e.KeyCode == Keys.Z) // { // ctrlPressed = true; // // 防止默认操作 // e.IsInputKey = true; // } // if (_IsEditMode && e.Control && e.KeyCode == Keys.Y) // { // ctrlPressed = true; // // 防止默认操作 // e.IsInputKey = true; // } // if (e.Control && e.KeyCode == Keys.R) // { // ctrlPressed = true; // // 防止默认操作 // e.IsInputKey = true; // } // } // public void setCenter(IBaseViewModel obj) // { // PointF position; // if (obj is LinkViewModel link) // position = link.Position; // else // position = obj.Position; // PointF currentPos = MapToScreen(WorldPointToMapPoint(position, obj.Elev)); // PointF centerScreen = new PointF(this.map.Width / 2, this.map.Height / 2); // var vector = GetRotateVector(centerScreen, currentPos); // MapCenter = new PointF( // MapCenter.X - vector.X / Zoom.X, // MapCenter.Y - vector.Y / Zoom.Y); // } // bool ctrlPressed = false; // #endregion // #region 右键菜单 // private void 转换ToolStripMenuItem_Click(object sender, EventArgs e) // { // var nodes = selectedNodes; // foreach (var obj in nodes) // { // if (obj == null) return; // var toolItem = sender as ToolStripItem; // NodeViewModel junc = null; // int i = 0; // string ID; // switch (toolItem.Text) // { // case "水表": // junc = _Network.AddMeter(obj.Position); // i = 0; // ID = $"{Default.GetPreString(junc)}{i}"; // while (_Nodes.Find(p0 => p0.ID == ID) != null) // { // i++; // ID = $"{Default.GetPreString(junc)}{i}"; // } // junc.ID = ID; // break; // case "基本节点": // junc = _Network.AddJunction(obj.Position, obj.Elev); // i = 0; // ID = $"{Default.GetPreString(junc)}{i}"; // while (_Nodes.Find(p0 => p0.ID == ID) != null) // { // i++; // ID = $"{Default.GetPreString(junc)}{i}"; // } // junc.ID = ID; // break; // case "水库": // junc = _Network.AddReservoir(obj.Position); // i = 0; // ID = $"{Default.GetPreString(junc)}{i}"; // while (_Nodes.Find(p0 => p0.ID == ID) != null) // { // i++; // ID = $"{Default.GetPreString(junc)}{i}"; // } // junc.ID = ID; // break; // case "水池": // junc = _Network.AddTank(obj.Position); // i = 0; // ID = $"{Default.GetPreString(junc)}{i}"; // while (_Nodes.Find(p0 => p0.ID == ID) != null) // { // i++; // ID = $"{Default.GetPreString(junc)}{i}"; // } // junc.ID = ID; // break; // } // junc.Level = obj.Level; // junc.Elev = obj.Elev; // junc.Demand = obj.Demand; // junc.Selected = true; // foreach (var p in _Links) // { // if (p.StartNode == obj) // { // p.StartNode = junc; // } // else if (p.EndNode == obj) // { // p.EndNode = junc; // } // } // selectedObjs.Add(junc); // selectedObjs.Remove(obj); // //MapObjectExtensions.AddCommand(obj, "Add", null, new List() { n }); // _Nodes.Remove(obj); // } // SetMapInvalidate(); // } // public void 删除ToolStripMenuItem_Click(object sender, EventArgs e) // { // DeleteChoosedObj(); // } // private void DeleteChoosedObj() // { // var list = _Network.Remove(selectedObjs); // MapObjectExtensions.AddCommand(_Network, "Remove", null, list); // selectedObjs.Clear(); // SetMapInvalidate(); // } // #endregion // #region 编辑模式/浏览模式切换工具 // private void toolStripComboBox_expandRepeater_ButtonClick(object sender, EventArgs e) // { // _IsEditMode = !_IsEditMode; // } // private void 浏览模式ToolStripMenuItem_Click(object sender, EventArgs e) // { // var obj = sender as ToolStripItem; // _IsEditMode = obj.Text == "编辑模式"; // } // #endregion // #region 分析工具 // private void 水平旋转ToolStripMenuItem_Click(object sender, EventArgs e) // { // var objs = GlobalObject.PropertyForm.selectionSet.selectedObjects; // var selectobjs = objs.FindAll(o => o is NodeViewModel); // if (selectobjs.Count <= 0) return; // if (!(selectobjs[0] as IBaseViewModel).isNode()) // { // MessageBox.Show("围绕选中节点进行平面旋转,请在属性列表中选中一个节点类对象"); // return; // } // NodeViewModel origin = selectobjs[0] as NodeViewModel; // var nodes = objs.FindAll(o => o.isNode()); // float jiaodu = float.Parse(toolStripTextBox_水平旋转角度.Text.ToString()); // var NewPositions = GetRotatedPoints(nodes.Select(n => n.Position).ToList(), origin.Position, jiaodu); // var OldPositions = nodes.Select(n => n.Position).ToList(); // for (int i = 0; i < nodes.Count; i++) // { // nodes[i].Position = NewPositions[i]; // } // MapObjectExtensions.AddCommand(nodes, "Position", OldPositions, NewPositions); // SetMapInvalidate(); // } // public List GetRotatedPoints(List points, PointF origin, float angle) // { // // 将角度转换为弧度 // float radians = angle * (float)Math.PI / 180.0f; // // 计算正余弦值 // float cos = (float)Math.Cos(radians); // float sin = (float)Math.Sin(radians); // // 定义结果集合,并遍历输入点集合进行旋转处理 // List result = new List(points.Count); // foreach (PointF point in points) // { // // 将点相对于旋转中心点平移,使其成为以原点为中心的坐标系 // float translatedX = point.X - origin.X; // float translatedY = point.Y - origin.Y; // // 应用旋转变换 // float rotatedX = translatedX * cos - translatedY * sin; // float rotatedY = translatedX * sin + translatedY * cos; // // 将点相对于原坐标系平移回去 // float finalX = rotatedX + origin.X; // float finalY = rotatedY + origin.Y; // // 添加到结果集合中 // result.Add(new PointF(finalX, finalY)); // } // return result; // } // public List GetRotatedPoints(List points, Vector3 line, float angle) // { // // 将角度转换为弧度 // float radians = (float)(angle * Math.PI / 180.0f); // // 根据旋转直线的方向矢量和旋转角度计算旋转矩阵 // float cos = (float)Math.Cos(radians); // float sin = (float)Math.Sin(radians); // float x = line.X; // float y = line.Y; // float z = line.Z; // float[,] rotationMatrix = new float[,] // { //{cos + x * x * (1 - cos), x * y * (1 - cos) - z * sin, x * z * (1 - cos) + y * sin}, //{y * x * (1 - cos) + z * sin, cos + y * y * (1 - cos), y * z * (1 - cos) - x * sin}, //{z * x * (1 - cos) - y * sin, z * y * (1 - cos) + x * sin, cos + z * z * (1 - cos)} // }; // // 定义结果集合,并遍历输入点集合进行旋转处理 // List result = new List(points.Count); // foreach (PointF3D point in points) // { // // 将点按照旋转中心线平移,使其成为以原点为中心的坐标系 // Vector3 translatedPoint = new Vector3(point.X - line.X, point.Y - line.Y, point.Z - line.Z); // // 应用旋转变换 // Vector3 rotatedPointVector = new Vector3( // translatedPoint.X * rotationMatrix[0, 0] + translatedPoint.Y * rotationMatrix[0, 1] + translatedPoint.Z * rotationMatrix[0, 2], // translatedPoint.X * rotationMatrix[1, 0] + translatedPoint.Y * rotationMatrix[1, 1] + translatedPoint.Z * rotationMatrix[1, 2], // translatedPoint.X * rotationMatrix[2, 0] + translatedPoint.Y * rotationMatrix[2, 1] + translatedPoint.Z * rotationMatrix[2, 2]); // // 将点相对于原坐标系平移回去 // float finalX = rotatedPointVector.X + line.X; // float finalY = rotatedPointVector.Y + line.Y; // float finalZ = rotatedPointVector.Z + line.Z; // // 将旋转后的点添加到结果集合中 // result.Add(new PointF3D(finalX, finalY, finalZ)); // } // return result; // } // private void 缩放ToolStripMenuItem_Click(object sender, EventArgs e) // { // var objs = GlobalObject.PropertyForm.selectionSet.selectedObjects; // var list = objs.FindAll(o => o is NodeViewModel); // if (list.Count <= 0) return; // if (list.Count >= 1 && !list[0].isNode()) // { // MessageBox.Show("围绕选中节点进行三维缩放,请在属性列表中选中一个[节点类]缩放中心对象"); // return; // } // NodeViewModel origin = list[0] as NodeViewModel; // var nodes = objs.FindAll(o => o.isNode()).Select(o => o as NodeViewModel).ToList(); // ToolStripMenuItem item = sender as ToolStripMenuItem; // float jiaodu; // switch (item.Text) // { // case "缩小2倍": // jiaodu = 0.5f; // break; // case "放大2倍": // jiaodu = 2f; // break; // default: // jiaodu = float.Parse(toolStripTextBox_缩放比例.Text.ToString()); // break; // } // var OldPositions = nodes.Select(n => n.Position3D).ToList(); // var NewPositions = ScalePoints(nodes.Select(n => n.Position3D).ToList(), origin.Position3D, jiaodu); // for (int i = 0; i < nodes.Count; i++) // { // nodes[i].X = NewPositions[i].X; // nodes[i].Y = NewPositions[i].Y; // nodes[i].Elev = NewPositions[i].Z; // } // MapObjectExtensions.AddCommand(nodes, "Position3D", OldPositions, NewPositions); // SetMapInvalidate(); // } // public static List ScalePoints(List points, PointF3D centerPoint, float scale) // { // //定义结果集合,并遍历输入点集合进行缩放处理 // List result = new List(points.Count); // foreach (PointF3D point in points) // { // //将点相对于缩放中心点平移,使其成为以原点为中心的坐标系 // Vector3 translatedPoint = new Vector3(point.X - centerPoint.X, point.Y - centerPoint.Y, point.Z - centerPoint.Z); // //应用缩放变换 // Vector3 scaledPointVector = new Vector3( // translatedPoint.X * scale + centerPoint.X, // translatedPoint.Y * scale + centerPoint.Y, // translatedPoint.Z * scale + centerPoint.Z); // //将缩放后的点添加到结果集合中 // result.Add(new PointF3D(scaledPointVector.X, scaledPointVector.Y, scaledPointVector.Z)); // } // return result; // } // private void btn_拓扑检查_Click(object sender, EventArgs e) // { // Dictionary> result = _Template.network.CheckValidate(); // if (result.Count > 0) // { // ListBox listBox1 = new ListBox(); // listBox1.Dock = DockStyle.Fill; // listBox1.Width = 200; // listBox1.Height = 400; // listBox1.Items.AddRange(result.Keys.ToArray()); // listBox1.SelectedIndexChanged += (s, e) => // { // //listBox2.Items.Clear(); // if (listBox1.SelectedIndex >= 0) // { // var arr = result[listBox1.SelectedItem.ToString()].ToHashSet(); // List Objs = new List(); // Objs.AddRange(_Nodes.Select(n => (NodeViewModel)n)); // Objs.AddRange(_Links.Select(l => (LinkViewModel)l)); // var nodes = _Nodes.FindAll(o => arr.Contains(o.ID)); // var links = _Links.FindAll(o => arr.Contains(o.ID)); // selectedObjs.ForEach(obj => obj.Selected = false); // selectedObjs.Clear(); // nodes.ForEach(obj => // { // obj.Selected = true; // selectedObjs.Add((NodeViewModel)obj); // }); // links.ForEach(obj => // { // obj.Selected = true; // selectedObjs.Add((LinkViewModel)obj); // }); // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // SetMapInvalidate(); // } // }; // Form ResultForm = new Form(); // ResultForm.Text = "拓扑检查结果"; // ResultForm.Width = 300; // ResultForm.Height = 400; // ResultForm.StartPosition = FormStartPosition.CenterScreen; // ResultForm.Controls.Add(listBox1); // ResultForm.MinimizeBox = false; // ResultForm.MaximizeBox = false; // ResultForm.Show(); // } // else // { // MessageBox.Show("拓扑检查通过"); // } // } // public void toolStripButton_计算_Click(object sender, EventArgs e) // { // if (_Template == null) // { // MessageBox.Show("请先打开文件"); // return; // } // } // public void 关阀搜索ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (selectedObjs.Count > 0)//&& selectedObjs[0] is Link l // { // var objs = selectedObjs.ToList(); // var selectsValve = objs.FindAll(o => o is ValveViewModel); // selectedObjs.ForEach(o => o.Selected = false); // selectedObjs.Clear(); // TraversePipeNetwork(objs, null, false); // selectsValve.ForEach(o => o.Selected = false); // this.SetMapInvalidate(); // } // } // /// 关阀分析(考虑水源的情况) // private void 关阀搜索考虑水源ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (selectedObjs.Count > 0) // { // var objs = selectedObjs.ToList(); // var selectsValve = objs.FindAll(o => o is ValveViewModel); // selectedObjs.ForEach(o => o.Selected = false); // selectedObjs.Clear(); // TraversePipeNetwork(objs, null); // selectsValve.ForEach(o => o.Selected = false); // this.SetMapInvalidate(); // } // } // List LinksToFindSource = null; // Dictionary> Sets = null; // Dictionary Sets_hasSource = null; // private void TraversePipeNetwork(List startObjs, HashSet visitedNodes = null, bool consider = true) // { // LinksToFindSource = new List(); // if (visitedNodes == null) // visitedNodes = new HashSet(); // startObjs.ForEach(o => // { // if (o is LinkViewModel l) // { // TraversePipeNetwork(l, visitedNodes); // } // else if (o is NodeViewModel n) // { // n.Links.Select(oo => oo as LinkViewModel).ToList().ForEach(link => TraversePipeNetwork(link, visitedNodes)); // } // }); // if (!consider) return; // Sets = new Dictionary>(); // Sets_hasSource = new Dictionary(); // LinksToFindSource.ForEach(l => // { // TraversePipeNetwork_Set(l, visitedNodes); // }); // foreach (var kp in Sets) // { // if (!Sets_hasSource[kp.Key]) // { // kp.Value.ForEach(o => // { // if (!(o is ValveViewModel)) // { // o.Selected = true; // selectedObjs.Add(o); // } // }); // } // } // if (GlobalObject.PropertyForm != null) // GlobalObject.PropertyForm.SetObjs(selectedObjs); // } // private void TraversePipeNetwork(LinkViewModel startLink, HashSet visitedNodes = null) // { // Queue queue = new Queue(); // queue.Enqueue(startLink); // if (visitedNodes == null) // visitedNodes = new HashSet(); // while (queue.Count > 0) // { // LinkViewModel currentLink = queue.Dequeue(); // foreach (var node in new NodeViewModel[] { currentLink.StartNode, currentLink.EndNode }) // { // if (!visitedNodes.Contains(node) && node != null) // { // visitedNodes.Add(node); // node.Selected = true; // selectedObjs.Add(node); // foreach (var link in node.ViewLinks) // { // if (!visitedNodes.Contains(link.StartNode) || !visitedNodes.Contains(link.EndNode)) // { // link.Selected = true; // selectedObjs.Add(link); // if (!(link is ValveViewModel)) // { // queue.Enqueue(link); // } // else // { // LinksToFindSource.Add(link); // } // } // } // } // } // } // } // private void TraversePipeNetwork_Set(LinkViewModel startLink, HashSet visitedNodes = null) // { // Queue queue = new Queue(); // queue.Enqueue(startLink); // if (visitedNodes == null) // visitedNodes = new HashSet(); // //visitedNodes.Add(startLink.StartNode); // //visitedNodes.Add(startLink.EndNode); // Sets.Add(startLink, new List()); // Sets_hasSource.Add(startLink, false); // while (queue.Count > 0) // { // LinkViewModel currentLink = queue.Dequeue(); // //Console.WriteLine("Traversing Link: " + currentLink.ID); // foreach (var node in new NodeViewModel[] { currentLink.StartNode, currentLink.EndNode }) // { // if (node == null) continue; // if (!visitedNodes.Contains(node)) // { // Sets[startLink].Add(node); // visitedNodes.Add(node); // if (node is TankViewModel || node is ReservoirViewModel) // { // Sets_hasSource[startLink] = true; // } // //Console.WriteLine("Visiting Node: " + node.ID); // foreach (var link in node.ViewLinks) // { // if (!visitedNodes.Contains(link.StartNode) || !visitedNodes.Contains(link.EndNode)) // { // Sets[startLink].Add(link); // queue.Enqueue(link); // } // } // } // else // { // foreach (var kp in Sets) // { // if (kp.Key != startLink && kp.Value.Contains(node)) // { // kp.Value.AddRange(Sets[startLink]); // Sets_hasSource[kp.Key] = Sets_hasSource[startLink] || Sets_hasSource[kp.Key]; // Sets.Remove(startLink); // Sets_hasSource.Remove(startLink); // startLink = kp.Key; // break; // } // } // } // } // } // } // private bool FindSouce(LinkViewModel startLink, HashSet visitedLinks, HashSet visitedLinks2, Dictionary hasSource = null) // { // foreach (var node in new NodeViewModel[] { startLink.StartNode, startLink.EndNode }) // { // if (!hasSource.ContainsKey(node)) // { // //hasSource.Add(node, false); // hasSource[node] = FindSouce(node, visitedLinks, visitedLinks2, hasSource); // } // if (hasSource[node] == true) return true; // } // return false; // } // private bool FindSouce(NodeViewModel startNode, HashSet visitedLinks, HashSet visitedLinks2, Dictionary hasSource = null) // { // foreach (var link in startNode.ViewLinks) // { // if (hasSource.ContainsKey(link) && hasSource[link] == true) return true; // if (visitedLinks.Contains(link) && startNode == link.StartNode) continue; // if (visitedLinks2.Contains(link) && startNode == link.EndNode) continue; // if (startNode == link.StartNode) // visitedLinks.Add(link); // else // visitedLinks2.Add(link); // if (!hasSource.ContainsKey(link)) // { // //hasSource.Add(link,false); // hasSource[link] = FindSouce(link, visitedLinks, visitedLinks2, hasSource); // } // if (hasSource[link] == true) return true; // } // return false; // } // //private void 联通性ToolStripMenuItem_Click(object sender, EventArgs e) // //{ // //if (selectedObjs.Count > 0)//&& selectedObjs[0] is Link l // //{ // //var objs = selectedObjs.FindAll(o => o is LinkViewModel).Select(o => o as LinkViewModel).ToList(); // //var visitedNodes = new HashSet(); // //objs.ForEach(o => TraversePipeNetworkALL(o, visitedNodes)); // //this.SetInvalidated(); // //} // //} // private void TraversePipeNetworkALL(LinkViewModel startLink, HashSet visitedNodes = null, int direction = 0) // { // Queue queue = new Queue(); // queue.Enqueue(startLink); // if (visitedNodes == null) // visitedNodes = new HashSet(); // //visitedNodes.Add(startLink.StartNode); // //visitedNodes.Add(startLink.EndNode); // while (queue.Count > 0) // { // LinkViewModel currentLink = queue.Dequeue(); // //Console.WriteLine("Traversing Link: " + currentLink.ID); // foreach (var node in new NodeViewModel[] { currentLink.StartNode, currentLink.EndNode }) // { // if (direction == 1 && currentLink.EN_FLOW >= 0 && node == currentLink.StartNode) continue; // if (direction == -1 && currentLink.EN_FLOW <= 0 && node == currentLink.EndNode) continue; // if (node != null && !visitedNodes.Contains(node)) // { // visitedNodes.Add(node); // node.Selected = true; // selectedObjs.Add(node); // //Console.WriteLine("Visiting Node: " + node.ID); // foreach (var link in node.ViewLinks) // { // if (!visitedNodes.Contains(link.StartNode) || !visitedNodes.Contains(link.EndNode)) // { // link.Selected = true; // selectedObjs.Add(link); // queue.Enqueue(link); // } // } // } // } // } // } // #endregion // #region 显示选项 // private void 显示节点ToolStripMenuItem_Click(object sender, EventArgs e) // { // _ShowJunction = true; // SetMapInvalidate(); // } // private void 隐藏节点ToolStripMenuItem_Click(object sender, EventArgs e) // { // _ShowJunction = false; // SetMapInvalidate(); // } // private void 大ToolStripMenuItem_Click(object sender, EventArgs e) // { // var item = sender as ToolStripItem; // if (item.Text == "大") // { // junction_multiply = 1f; // } // else if (item.Text == "中") // { // junction_multiply = 0.6667f; // } // else // { // junction_multiply = 0.4f; // } // SetMapInvalidate(); // } // private void 显示阀门ToolStripMenuItem_Click(object sender, EventArgs e) // { // _ShowValve = true; // SetMapInvalidate(); // } // private void 隐藏阀门ToolStripMenuItem_Click(object sender, EventArgs e) // { // _ShowValve = false; // SetMapInvalidate(); // } // private void 大ToolStripMenuItem1_Click(object sender, EventArgs e) // { // var item = sender as ToolStripItem; // if (item.Text == "大") // { // Link_multiply = 1f; // } // else if (item.Text == "中") // { // Link_multiply = 0.6667f; // } // else // { // Link_multiply = 0.4f; // } // SetMapInvalidate(); // } // #endregion // #endregion 二、工具栏 // #region 方法 // private void 标高推测ToolStripMenuItem_Click(object sender, EventArgs e) // { // int num = UpdateNodesEle(); // if (num > 0) // { // MessageBox.Show($"更新成功,更新节点数量:{num}个"); // } // else // { // MessageBox.Show($"没有需要更新的节点"); // } // } // public int UpdateNodesEle() // { // int num = 0; // foreach (NodeViewModel node in _Nodes) // { // if (node.Elev == 0 && node is JunctionViewModel) // { // HashSet nodeSet = new HashSet(); // nodeSet.Add(node); // List nonZeroNeighbors = new List(); // FindNonZeroNeighbors(node, nonZeroNeighbors, nodeSet); // if (nonZeroNeighbors.Count != 0) // { // float sum = 0; // float weightSum = 0; // foreach (NodeViewModel neighbor in nonZeroNeighbors) // { // float dist = Get_dist(node.Position, neighbor.Position); // if (dist == 0) // { // dist = 0.0000000001f; // } // float weight = 1 / dist;// CalculateWeight(node, neighbor); // sum += neighbor.Elev * weight; // weightSum += weight; // } // float average = sum / weightSum; // node.Elev = average; // num++; // } // } // } // return num; // } // private void FindNonZeroNeighbors(NodeViewModel node, List result, HashSet origin) // { // foreach (LinkViewModel link in node.ViewLinks) // { // NodeViewModel neighbor = null; // if (link.StartNode == node) // { // neighbor = link.EndNode; // } // else // { // neighbor = link.StartNode; // } // if (neighbor.Elev != 0) // { // result.Add(neighbor); // } // else if (!origin.Contains(neighbor)) // { // origin.Add(neighbor); // FindNonZeroNeighbors(neighbor, result, origin); // } // } // } // private void 标高导出ToolStripMenuItem_Click(object sender, EventArgs e) // { // DataTable dt = new DataTable(); // dt.Columns.Add("ID"); // dt.Columns.Add("Elev", typeof(float)); // foreach (NodeViewModel node in _Nodes) // { // if (node is JunctionViewModel junction) // { // var dr = dt.NewRow(); // dr.ItemArray = new object[] { junction.ID, junction.Elev }; // dt.Rows.Add(dr); // } // } // dtToSql(dt); // } // void dtToCsv(DataTable dt) // { // // 创建 SaveFileDialog 对象 // SaveFileDialog saveFileDialog = new SaveFileDialog(); // saveFileDialog.Filter = "CSV Files (*.csv)|*.csv"; // saveFileDialog.FileName = "output.csv"; // // 如果用户选择了保存位置和文件名,则执行保存操作 // if (saveFileDialog.ShowDialog() == DialogResult.OK) // { // // 获取用户选择的保存路径和文件名 // string filePath = saveFileDialog.FileName; // // 假设 dt 是包含数据的 DataTable 对象 // // 构建 CSV 字符串 // StringBuilder csvContent = new StringBuilder(); // // 写入表头 // foreach (DataColumn column in dt.Columns) // { // csvContent.Append(column.ColumnName); // csvContent.Append(","); // } // csvContent.AppendLine(); // // 写入数据行 // foreach (DataRow row in dt.Rows) // { // for (int i = 0; i < dt.Columns.Count; i++) // { // csvContent.Append(row[i]); // csvContent.Append(","); // } // csvContent.AppendLine(); // } // // 将 CSV 内容写入文件 // File.WriteAllText(filePath, csvContent.ToString()); // // 显示保存成功消息框 // MessageBox.Show("文件保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // } // void dtToSql(DataTable dt) // { // // 创建 SaveFileDialog 对象 // SaveFileDialog saveFileDialog = new SaveFileDialog(); // saveFileDialog.Filter = "Txt Files (*.txt)|*.txt"; // // 如果用户选择了保存位置和文件名,则执行保存操作 // if (saveFileDialog.ShowDialog() == DialogResult.OK) // { // // 获取用户选择的保存路径和文件名 // string filePath = saveFileDialog.FileName; // // 假设 dt 是包含数据的 DataTable 对象 // string tableString = @" //IF OBJECT_ID('Elev', 'U') IS NOT NULL //BEGIN //-- 清空表 //TRUNCATE TABLE Elev; //END //ELSE //BEGIN //-- 创建表 //CREATE TABLE Elev ( //ID NVARCHAR(50), //Elev REAL //); //END //"; // // 构建 CSV 字符串 // StringBuilder csvContent = new StringBuilder(); // csvContent.AppendLine(tableString); // //// 写入表头 // //foreach (DataColumn column in dt.Columns) // //{ // //csvContent.Append(column.ColumnName); // //csvContent.Append(","); // //} // //csvContent.AppendLine(); // int i = 0; // int j = 0; // while (i < dt.Rows.Count) // { // if (j == 0) csvContent.AppendLine("INSERT INTO Elev (ID, Elev) VALUES"); // // 写入数据行 // DataRow row = dt.Rows[i]; // csvContent.Append($"('{row[0]}',{row[1]})"); // csvContent.Append(i == dt.Rows.Count - 1 || j == 999 ? ";" : ","); // csvContent.AppendLine(); // i++; // j++; // if (j == 1000) j = 0; // } // // 将 CSV 内容写入文件 // File.WriteAllText(filePath, csvContent.ToString()); // // 显示保存成功消息框 // MessageBox.Show("文件保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // } // } // private void 导入jsonToolStripMenuItem_Click(object sender, EventArgs e) // { // var ofd = new OpenFileDialog(); // ofd.Filter = "json文件|*.json"; // var result = ofd.ShowDialog(); // if (result == DialogResult.OK) // { // _Template = new Template(new Guid().ToString(), "新建", "复制", TemplateType.其他); // string json = File.ReadAllText(ofd.FileName); // _Template.network = JsonConvert.DeserializeObject(json); // _Template.network.BuildRelation(); // TemplateList.AddTemp(_Template); // LoadData(); // } // } // public void buttonUndo_Click(object sender, EventArgs e) // { // SetMapInvalidate(); // GlobalObject.PropertyForm.propertyGrid.Refresh(); // MapObjectExtensions.Undo(); // } // public void buttonRedo_Click(object sender, EventArgs e) // { // SetMapInvalidate(); // GlobalObject.PropertyForm.propertyGrid.Refresh(); // MapObjectExtensions.Redo(); // } // public void toolStripButton_save_ButtonClick(object sender, EventArgs e) // { // if (_Template == null) return; // if (!_IsEditMode) // { // return; // } // else // { // } // } // /// 批量一键生成楼层模型 // 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; // StringBuilder sb = new StringBuilder(); // sb.AppendLine("[COORDINATES]"); // sb.AppendLine(";Node X-Coord Y-Coord"); // _Nodes.ForEach(n => // { // var p = WorldPointToMapPoint((NodeViewModel)n); // sb.AppendLine($"{n.ID} {p.X} {p.Y}"); // }); // SaveFileDialog saveFileDialog = new SaveFileDialog(); // saveFileDialog.Filter = "Inp Files (*.inp)|*.inp"; // saveFileDialog.InitialDirectory = Directory.GetCurrentDirectory() + $@"\template\"; // if (_filePath != null) saveFileDialog.FileName = _filePath; // if (saveFileDialog.ShowDialog() == DialogResult.OK) // { // string filePath = saveFileDialog.FileName; // // 使用 filePath 变量来保存文件 // //temp.路径 = filePath; // //_filePath = filePath; // } // } // private void 连通性检查ToolStripMenuItem1_Click(object sender, EventArgs e) // { // if (selectedObjs.Count > 0)//&& selectedObjs[0] is Link l // { // var objs = selectedObjs.FindAll(o => o is LinkViewModel).Select(o => o as LinkViewModel).ToList(); // if (objs.Count == 0) selectedObjs.FindAll(o => o is NodeViewModel).Select(o => o as NodeViewModel).ToList().ForEach(o => objs.AddRange(o.Links.Select(l => l as LinkViewModel).ToList())); // //objs去掉重复的元素 // objs = objs.Distinct().ToList(); // var visitedNodes = new HashSet(); // objs.ForEach(o => TraversePipeNetworkALL(o, visitedNodes)); // this.SetMapInvalidate(); // } // } // private void 下游连通性ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (selectedObjs.Count > 0)//&& selectedObjs[0] is Link l // { // var objs = selectedObjs.FindAll(o => o is LinkViewModel).Select(o => o as LinkViewModel).ToList(); // if (objs.Count == 0) selectedObjs.FindAll(o => o is NodeViewModel).Select(o => o as NodeViewModel).ToList().ForEach(o => // { // objs.AddRange(o.Links.Select(oo => oo as LinkViewModel).ToList().FindAll(oo => oo.StartNode == o ? oo.EN_FLOW > 0 : oo.EN_FLOW < 0)); // }); // //objs去掉重复的元素 // objs = objs.Distinct().ToList(); // var visitedNodes = new HashSet(); // objs.ForEach(o => TraversePipeNetworkALL(o, visitedNodes, 1)); // this.SetMapInvalidate(); // } // } // public void 复制ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (hoveredObjs.Count <= 0 || !(hoveredObjs[0] is NodeViewModel)) // { // MessageBox.Show("请将鼠标悬停在一个节点对象上,作为基准点"); // return; // } // if (selectedObjs.Count <= 0 || selectedNodes.Count <= 0) // { // MessageBox.Show("请选择要复制的对象"); // return; // } // _OperaNode = hoveredObjs[0] as NodeViewModel; // MapViewNetWork net = new MapViewNetWork(); // net.StartPoint = _OperaNode; // net.Nodes.AddRange(selectedObjs.FindAll(o => o is NodeViewModel).Select(o => o as NodeViewModel)); // net.Links.AddRange(selectedObjs.FindAll(o => o is LinkViewModel).Select(o => o as LinkViewModel)); // string json = net.WriteToJson(); // try // { // Clipboard.SetText(json); // this.SetMapInvalidate(); // } // catch // { // //提醒 // } // } // public void 粘贴ToolStripMenuItem1_Click(object sender, EventArgs e) // { // { // var net = new MapViewNetWork(); // string json = Clipboard.GetText(); // net.ReadFromJson(json); // if (net.StartPoint == null) return; // string SID = net.StartPoint.ID; // net.StartPoint = net.Nodes.Find(n => n.ID == SID); // 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; // var position = new Point(offsetX, offsetY); // net.BuildRelation(); // //var basePoint = MapPointToWorldPoint(ScreenToMap(position, net.StartPoint.Elev), net.StartPoint.Elev); // var mPos = _MousePosition; // if (hoveredObjs.Count > 0 && hoveredObjs[0] is NodeViewModel minNode) // { // 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); // selectedObjs.Clear(); // 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(); // } // else // { // var basePoint = MapPointToWorldPoint(_MousePosition, net.StartPoint.Elev); // net.Nodes.ForEach(obj => // { // obj.X = obj.X + basePoint.X - minPoint.X; // obj.Y = obj.Y + basePoint.Y - minPoint.Y; // }); // selectedObjs.ForEach(o => o.Selected = false); // selectedObjs.Clear(); // 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(); // } // } // } // private void 增量保存ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (_Template == null) return; // if (!_IsEditMode) // { // return; // } // else // { // bool isReplace = true; // //isReplace = !message.show("模板选择", "使用模板新增/替换当前文件", MessageBoxButtons.YesNo); // } // } // private void 设为关闭ToolStripMenuItem_Click(object sender, EventArgs e) // { // selectedObjs.ForEach(obj => { if (obj is LinkViewModel link) link.Status = StatusType.CLOSED; }); // SetMapInvalidate(); // } // private void 显示全部楼层ToolStripMenuItem_Click(object sender, EventArgs e) // { // //this.mapOption.ShowFloor = int.MinValue; // _Network.MapObjects.ForEach(o => o.Visible = true); // this.SetMapInvalidate(); // } // private void 保存楼层视角ToolStripMenuItem_Click(object sender, EventArgs e) // { // //if (_Template?.Floors!=null) // //{ // //var fl = _Template.Floors.Find(f => f.FloorIndex == this.mapOption.ShowFloor); // //if (fl!=null)fl.MapView = this.mapOption.Copy(); // //} // } // public void 南北对齐ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (selectedNodes.Count < 1) return; // List list = new List(); // List list1 = new List(); // selectedNodes.ForEach(n => { list.Add(n.X); n.X = selectedNodes[0].X; list1.Add(n.X); }); // MapObjectExtensions.AddCommand(selectedNodes, "X", list, list1); // this.SetMapInvalidate(); // } // public void 东西对齐ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (selectedNodes.Count < 1) return; // List list = new List(); // List list1 = new List(); // selectedNodes.ForEach(n => { list.Add(n.Y); n.Y = selectedNodes[0].Y; list1.Add(n.Y); }); // MapObjectExtensions.AddCommand(selectedNodes, "Y", list, list1); // this.SetMapInvalidate(); // } // public void 竖直对齐ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (selectedNodes.Count < 1) return; // List list = new List(); // List list1 = new List(); // selectedNodes.ForEach(n => { list.Add(n.Position); n.Position = selectedNodes[0].Position; list1.Add(n.Position); }); // MapObjectExtensions.AddCommand(selectedNodes, "Position", list, list1); // this.SetMapInvalidate(); // } // public void 自动对齐ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (selectedNodes.Count < 3) return; // List OldPosition3Ds = selectedNodes.Select(n => n.Position3D).ToList(); // List NewPosition3Ds = ProjectPointsToLine(OldPosition3Ds); // for (int i = 0; i < selectedNodes.Count; i++) // { // selectedNodes[i].Position3D = NewPosition3Ds[i]; // } // MapObjectExtensions.AddCommand(selectedNodes, "Position3D", OldPosition3Ds, NewPosition3Ds); // this.SetMapInvalidate(); // } // List ProjectPointsToLine(List points) // { // // 使用最小二乘法构造直线,并将点投影到直线上 // // 计算均值 // double sumX = 0; // double sumY = 0; // double sumZ = 0; // foreach (PointF3D point in points) // { // sumX += point.X; // sumY += point.Y; // sumZ += point.Z; // } // double meanX = sumX / points.Count; // double meanY = sumY / points.Count; // double meanZ = sumZ / points.Count; // // 计算最小二乘法拟合直线的参数 // double sumXY = 0; // double sumX2 = 0; // foreach (PointF3D point in points) // { // double devX = point.X - meanX; // double devY = point.Y - meanY; // double devZ = point.Z - meanZ; // sumXY += devX * devY; // sumX2 += devX * devX; // } // double slope = sumXY / sumX2; // double interceptY = meanY - slope * meanX; // double interceptZ = meanZ - slope * meanX; // // 计算点投影到直线上的坐标 // List projectedPoints = new List(); // foreach (PointF3D point in points) // { // double projectedY = slope * point.X + interceptY; // double projectedZ = slope * point.X + interceptZ; // projectedPoints.Add(new PointF3D(point.X, (float)projectedY, (float)projectedZ)); // } // return projectedPoints; // } // public void 添加底图ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (_Template == null) return; // OpenFileDialog openFileDialog = new OpenFileDialog(); // openFileDialog.Filter = "Image Files (*.bmp;*.jpg;*.jpeg;*.png;*.gif)|*.bmp;*.jpg;*.jpeg;*.png;*.gif"; // openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); // if (openFileDialog.ShowDialog() == DialogResult.OK) // { // var backgroundImagePath = openFileDialog.FileName; // Global.ClearFileReadOnly(_Template.BackGroundImg_FullPath); // FileCopy.Copy(backgroundImagePath, _Template.BackGroundImg_FullPath, true); // 设置底图ToolStripMenuItem_Click(1, new EventArgs()); // } // } // bool _isSettingBackGroundPictur = false; // public void 设置底图ToolStripMenuItem_Click(object sender, EventArgs e) // { // string inputValue = "0";// Prompt.ShowDialog("请输入底图标高", ""); // float BackGroundElev = 0; // if (float.TryParse(inputValue, out float result)) // { // BackGroundElev = result; // } // else // { // BackGroundElev = 0; // } // _Template.BackGroundElev = BackGroundElev; // _mouseState = MouseState.设置底图范围; // this._lastCursor = this.Cursor; // this.Cursor = Cursors.Cross; // } // public void 显示隐藏底图ToolStripMenuItem_Click(object sender, EventArgs e) // { // mapOption.isShowPic = !mapOption.isShowPic; // SetMapInvalidate(); // } // private dict param = null; // public void 清除底图ToolStripMenuItem_Click(object sender, EventArgs e) // { // mapOption.isShowPic = false; // SetMapInvalidate(); // try // { // File.Delete(_Template.BackGroundImg_FullPath); // } // catch // { // } // } // private void label_zoom_Click(object sender, EventArgs e) // { // string inputValue = Prompt.ShowDialog("请输入比例", ""); // if (float.TryParse(inputValue, out float result)) // { // zoom = result; // } // } // private void label_file_DoubleClick(object sender, EventArgs e) // { // if (_filePath == null) return; // FileInfo fi = new FileInfo(_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); // System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{_filePath}\""); // } // private void 设为立管点ToolStripMenuItem_Click(object sender, EventArgs e) // { // if (selectedNodes.Count == 1) // { // _Template.Node2 = _EndPoint = selectedNodes[0].ID; // } // } // private void 显示水流ToolStripMenuItem_Click(object sender, EventArgs e) // { // _Template.network.MapObjects.ForEach(o => o.Selected = false); // selectedObjs.Clear(); // _Template.network.Links.ForEach(link => // { // if (link.EN_FLOW != 0) // { // selectedObjs.Add(link); // link.Selected = true; // NodeViewModel node = link.StartNode; // node.Selected = true; // if (!selectedObjs.Contains(node)) selectedObjs.Add(node); // node = link.EndNode; // node.Selected = true; // if (!selectedObjs.Contains(node)) selectedObjs.Add(node); // } // }); // this.SetMapInvalidate(); // } // private void 全选ToolStripMenuItem_Click(object sender, EventArgs e) // { // selectedObjs.Clear(); // _Template.network.MapObjects.ForEach(o => // { // if (o.Visible) // { // o.Selected = true; // selectedObjs.Add(o); // } // }); // this.SetMapInvalidate(); // } // private void 反选ToolStripMenuItem_Click(object sender, EventArgs e) // { // _Template.network.MapObjects.ForEach(o => // { // if (o.Visible) // { // if (o.Selected) // { // o.Selected = false; // selectedObjs.Remove(o); // } // else // { // o.Selected = true; // selectedObjs.Add(o); // } // } // }); // this.SetMapInvalidate(); // } // private void 显示状态ToolStripMenuItem_Click(object sender, EventArgs e) // { // _Template.mapOption._ShowStatus = true; // this.SetMapInvalidate(); // } // private void 隐藏状态ToolStripMenuItem_Click(object sender, EventArgs e) // { // _Template.mapOption._ShowStatus = false; // this.SetMapInvalidate(); // } // private void 显示流向ToolStripMenuItem_Click(object sender, EventArgs e) // { // _Template.mapOption._ShowFlowDirection = true; // this.SetMapInvalidate(); // } // private void 隐藏流向ToolStripMenuItem_Click(object sender, EventArgs e) // { // _Template.mapOption._ShowFlowDirection = false; // this.SetMapInvalidate(); // } // private void 方向修复ToolStripMenuItem_Click(object sender, EventArgs e) // { // _Network.Links.ForEach(l => // { // //根据l.EN_FLOW重新设置l.STARTNODE和l.ENDNODE // if (l.EN_FLOW < 0) // { // var node = l.StartNode; // l.StartNode = l.EndNode; // l.EndNode = node; // } // }); // } // private void 刷新楼层ToolStripMenuItem_Click(object sender, EventArgs e) // { // ToolStripMenuItem_Floor.DropDownItems.Clear(); // var mapobjects = _Network.MapObjects; // TagList tags = new TagList(); // foreach (var item in mapobjects) // { // if (item.Tags != null) // tags.AddRange(item.Tags); // } // var t = tags.Distinct().ToList(); // tags.Clear(); // tags.AddRange(t); // for (int i = -10; i < 1000; i++) // { // string tagstring = i.ToString() + "楼"; // if (tags.Contains(tagstring)) // { // var item = ToolStripMenuItem_Floor.DropDownItems.Add(i.ToString() + "楼"); // item.Click += (oo, ee) => // { // mapobjects.ForEach(o => // { // if (o.Tags.Contains(tagstring)) // { // o.Visible = true; // } // else // { // o.Visible = false; // } // }); // this.SetMapInvalidate(); // }; // } // } // this.SetMapInvalidate(); // } // private void 显示所有隐藏内容ToolStripMenuItem_Click(object sender, EventArgs e) // { // _Network.MapObjects.ForEach(o => o.Visible = true); // this.SetMapInvalidate(); // } // public void toolStripButton_CalcMiniLoss_Click(object sender, EventArgs e) // { // _Network.SetNodeDemand(); // _Network.CalcLinkMinorLoss(); // } // private void toolStripButton_ClearMinor_Click(object sender, EventArgs e) // { // _Network.ClearMinorLoss(); // } // private void 显示流向ToolStripMenuItem1_Click(object sender, EventArgs e) // { // _isShowDirection = !_isShowDirection; // } // bool _isShowDirection = false; // private void 颜色分级管理ToolStripMenuItem_Click(object sender, EventArgs e) // { // //Form_Colour form_Colour = new Form_Colour(_Template.Colours, _Template); // //form_Colour.Show(this); // } // private bool __needpaintall = false; // 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; // var doubles = _Template.network.getMinMax(type); // var colour = new Colour(type, null, type.ToString()); // List 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; // var doubles = _Template.network.getMinMax(type); // var colour = new Colour(type, null, type.ToString()); // List 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) // { // //正交模式的全局变量开关 // _isOrtho = !_isOrtho; // } // private void 楼层管理ToolStripMenuItem_Click(object sender, EventArgs e) // { // /*if (_Template.Regions == null) // { // _Template.Regions = new List(); // } // Form_EditFloors form_EditFloors = new Form_EditFloors(_Template.Regions); // form_EditFloors.Show(this);*/ // } // #endregion //} //partial class MapViewer //{ // /// 必需的设计器变量。 // private IContainer components = null; // /// 清理所有正在使用的资源。 // /// 如果应释放托管资源,为 true;否则为 false。 // protected override void Dispose(bool disposing) // { // if (disposing && (components != null)) // { // components.Dispose(); // } // base.Dispose(disposing); // } // #region 组件设计器生成的代码 // /// 设计器支持所需的方法 - 不要修改 // /// 使用代码编辑器修改此方法的内容。 // #region 三、设计器 // private void InitializeComponent() // { // components = new Container(); // ComponentResourceManager resources = new ComponentResourceManager(typeof(MapViewer)); // statusStrip1 = new StatusStrip(); // label_center = new ToolStripStatusLabel(); // toolStripStatusLabel_rotation = new ToolStripStatusLabel(); // label_zoom = new ToolStripStatusLabel(); // label_mouse = new ToolStripStatusLabel(); // toolStripStatusLabel_split1 = new ToolStripStatusLabel(); // label_ZZ = new ToolStripStatusLabel(); // toolStripStatusLabel_split2 = new ToolStripStatusLabel(); // label_file = new ToolStripStatusLabel(); // panel1 = new Panel(); // toolStrip1 = new ToolStrip(); // toolStripSplitButton2 = new ToolStripSplitButton(); // 新建ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator1 = new ToolStripSeparator(); // 打开文件位置ToolStripMenuItem = new ToolStripMenuItem(); // ePA中打开ToolStripMenuItem = new ToolStripMenuItem(); // 旧版打开ToolStripMenuItem = new ToolStripMenuItem(); // toolStripButton_save = new ToolStripSplitButton(); // 另存为ToolStripMenuItem = new ToolStripMenuItem(); // 以当前视角另存ToolStripMenuItem = new ToolStripMenuItem(); // 增量保存ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator2 = new ToolStripSeparator(); // toolStripButton_普通 = new ToolStripButton(); // toolStripButton_新建节点 = new ToolStripButton(); // toolStripButton_新建管线 = new ToolStripButton(); // toolStripButton_新建立管 = new ToolStripButton(); // toolStripButton_添加水库 = new ToolStripButton(); // toolStripButton_添加水池 = new ToolStripButton(); // toolStripButton_添加水泵 = new ToolStripButton(); // toolStripButton_添加阀门 = new ToolStripButton(); // toolStripButton_添加水表 = new ToolStripButton(); // toolStripButton_重复器 = new ToolStripButton(); // buttonUndo = new ToolStripButton(); // buttonRedo = new ToolStripButton(); // toolStripButton_ClearMinor = new ToolStripButton(); // toolStripSeparator4 = new ToolStripSeparator(); // toolStripButton_刷新 = new ToolStripButton(); // btn_水量初分配 = new ToolStripButton(); // toolStripDropDownButton_工具 = new ToolStripDropDownButton(); // 水平旋转ToolStripMenuItem = new ToolStripMenuItem(); // toolStripTextBox_水平旋转角度 = new ToolStripTextBox(); // 轴旋转ToolStripMenuItem = new ToolStripMenuItem(); // 轴镜像ToolStripMenuItem = new ToolStripMenuItem(); // 缩放ToolStripMenuItem = new ToolStripMenuItem(); // toolStripTextBox_缩放比例 = new ToolStripTextBox(); // toolStripMenuItem_放大2倍 = new ToolStripMenuItem(); // toolStripMenuItem_缩小2倍 = new ToolStripMenuItem(); // toolStripSeparator7 = new ToolStripSeparator(); // 关阀分析ToolStripMenuItem = new ToolStripMenuItem(); // 关阀分析不考虑水源ToolStripMenuItem = new ToolStripMenuItem(); // 连通性检查ToolStripMenuItem1 = new ToolStripMenuItem(); // 下游连通性ToolStripMenuItem = new ToolStripMenuItem(); // 上游连通性ToolStripMenuItem = new ToolStripMenuItem(); // 标高推测ToolStripMenuItem = new ToolStripMenuItem(); // 标高导出ToolStripMenuItem = new ToolStripMenuItem(); // 显示水流ToolStripMenuItem = new ToolStripMenuItem(); // 方向修复ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator12 = new ToolStripSeparator(); // 复制ToolStripMenuItem = new ToolStripMenuItem(); // 粘贴ToolStripMenuItem = new ToolStripMenuItem(); // 删除ToolStripMenuItem1 = new ToolStripMenuItem(); // toolStripSeparator15 = new ToolStripSeparator(); // 对齐ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator16 = new ToolStripSeparator(); // 东西对齐ToolStripMenuItem = new ToolStripMenuItem(); // 南北对齐ToolStripMenuItem = new ToolStripMenuItem(); // 竖直对齐ToolStripMenuItem = new ToolStripMenuItem(); // 自动对齐ToolStripMenuItem = new ToolStripMenuItem(); // 排列ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator22 = new ToolStripSeparator(); // 楼层管理ToolStripMenuItem = new ToolStripMenuItem(); // 水量分配ToolStripMenuItem = new ToolStripMenuItem(); // 计算局部损失ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator8 = new ToolStripSeparator(); // toolStripSplitButton1 = new ToolStripSplitButton(); // 重置ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator14 = new ToolStripSeparator(); // toolStripMenuItem8 = new ToolStripMenuItem(); // toolStripMenuItem7 = new ToolStripMenuItem(); // toolStripMenuItem6 = new ToolStripMenuItem(); // toolStripMenuItem5 = new ToolStripMenuItem(); // toolStripMenuItem4 = new ToolStripMenuItem(); // toolStripMenuItem3 = new ToolStripMenuItem(); // toolStripMenuItem2 = new ToolStripMenuItem(); // toolStripSeparator3 = new ToolStripSeparator(); // ToolStripMenuItem_Floor = new ToolStripMenuItem(); // 显示全部楼层ToolStripMenuItem = new ToolStripMenuItem(); // 保存楼层视角ToolStripMenuItem = new ToolStripMenuItem(); // 刷新楼层ToolStripMenuItem = new ToolStripMenuItem(); // toolStripComboBox_浏览模式 = new ToolStripSplitButton(); // 浏览模式ToolStripMenuItem = new ToolStripMenuItem(); // 编辑模式ToolStripMenuItem = new ToolStripMenuItem(); // toolStripDropDownButton1 = new ToolStripDropDownButton(); // 显示节点ToolStripMenuItem = new ToolStripMenuItem(); // 隐藏节点ToolStripMenuItem = new ToolStripMenuItem(); // 节点大小ToolStripMenuItem = new ToolStripMenuItem(); // 大ToolStripMenuItem = new ToolStripMenuItem(); // 中ToolStripMenuItem = new ToolStripMenuItem(); // 小ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator10 = new ToolStripSeparator(); // 显示阀门ToolStripMenuItem = new ToolStripMenuItem(); // 隐藏阀门ToolStripMenuItem = new ToolStripMenuItem(); // 管线粗细ToolStripMenuItem = new ToolStripMenuItem(); // 大ToolStripMenuItem1 = new ToolStripMenuItem(); // 中ToolStripMenuItem1 = new ToolStripMenuItem(); // 小ToolStripMenuItem1 = new ToolStripMenuItem(); // toolStripSeparator13 = new ToolStripSeparator(); // 缩放级别ToolStripMenuItem = new ToolStripMenuItem(); // 放大ToolStripMenuItem2 = new ToolStripMenuItem(); // 正常ToolStripMenuItem = new ToolStripMenuItem(); // 缩小ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator5 = new ToolStripSeparator(); // 隐藏内容ToolStripMenuItem = new ToolStripMenuItem(); // 显示所有隐藏内容ToolStripMenuItem = new ToolStripMenuItem(); // 隐藏ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator17 = new ToolStripSeparator(); // 添加底图ToolStripMenuItem = new ToolStripMenuItem(); // 设置底图ToolStripMenuItem = new ToolStripMenuItem(); // 显示隐藏底图ToolStripMenuItem = new ToolStripMenuItem(); // 清除底图ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator18 = new ToolStripSeparator(); // 显示状态ToolStripMenuItem = new ToolStripMenuItem(); // 隐藏状态ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator19 = new ToolStripSeparator(); // 显示流向ToolStripMenuItem = new ToolStripMenuItem(); // 隐藏流向ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator20 = new ToolStripSeparator(); // 颜色分级管理ToolStripMenuItem = new ToolStripMenuItem(); // cb_Node_Colour = new ToolStripComboBox(); // cb_Link_Colour = new ToolStripComboBox(); // tb_颜色分级设置 = new ToolStripButton(); // toolStripSeparator21 = new ToolStripSeparator(); // 右键_Menu = new ContextMenuStrip(components); // 视角ToolStripMenuItem = new ToolStripMenuItem(); // 默认视角ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator23 = new ToolStripSeparator(); // 俯视图ToolStripMenuItem = new ToolStripMenuItem(); // 正视图ToolStripMenuItem = new ToolStripMenuItem(); // 重置视角ToolStripMenuItem = new ToolStripMenuItem(); // 对齐ToolStripMenuItem1 = new ToolStripMenuItem(); // 东西对齐ToolStripMenuItem1 = new ToolStripMenuItem(); // 南北对齐ToolStripMenuItem1 = new ToolStripMenuItem(); // 竖直对齐ToolStripMenuItem1 = new ToolStripMenuItem(); // 自动对齐ToolStripMenuItem1 = new ToolStripMenuItem(); // toolStripSeparator6 = new ToolStripSeparator(); // 设置长度ToolStripMenuItem = new ToolStripMenuItem(); // 设为关闭ToolStripMenuItem = new ToolStripMenuItem(); // 设为立管点ToolStripMenuItem = new ToolStripMenuItem(); // 设为隐藏ToolStripMenuItem = new ToolStripMenuItem(); // 显示ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator11 = new ToolStripSeparator(); // 复制ToolStripMenuItem1 = new ToolStripMenuItem(); // 粘贴ToolStripMenuItem1 = new ToolStripMenuItem(); // 转换为ToolStripMenuItem = new ToolStripMenuItem(); // 基本节点ToolStripMenuItem = new ToolStripMenuItem(); // 用户点ToolStripMenuItem = new ToolStripMenuItem(); // 水库ToolStripMenuItem = new ToolStripMenuItem(); // 水池ToolStripMenuItem = new ToolStripMenuItem(); // 删除ToolStripMenuItem = new ToolStripMenuItem(); // toolStripSeparator9 = new ToolStripSeparator(); // 全选ToolStripMenuItem = new ToolStripMenuItem(); // 反选ToolStripMenuItem = new ToolStripMenuItem(); // propertyForm = new PropertyForm(); // timer_draw = new System.Windows.Forms.Timer(components); // map = new DMap(); // CubeView = new DMap(); // statusStrip1.SuspendLayout(); // panel1.SuspendLayout(); // toolStrip1.SuspendLayout(); // 右键_Menu.SuspendLayout(); // SuspendLayout(); // // // // statusStrip1 // // // statusStrip1.Items.AddRange(new ToolStripItem[] { label_center, toolStripStatusLabel_rotation, label_zoom, label_mouse, toolStripStatusLabel_split1, label_ZZ, toolStripStatusLabel_split2, label_file }); // statusStrip1.Location = new Point(0, 578); // statusStrip1.Name = "statusStrip1"; // statusStrip1.Size = new Size(1051, 22); // statusStrip1.TabIndex = 0; // statusStrip1.Text = "statusStrip1"; // // // // label_center // // // label_center.Name = "label_center"; // label_center.Size = new Size(73, 17); // label_center.Text = "center:0,0"; // label_center.Click += label_center_Click; // // // // toolStripStatusLabel_rotation // // // toolStripStatusLabel_rotation.Name = "toolStripStatusLabel_rotation"; // toolStripStatusLabel_rotation.Size = new Size(83, 17); // toolStripStatusLabel_rotation.Text = "rotation:0,0"; // // // // label_zoom // // // label_zoom.Name = "label_zoom"; // label_zoom.Size = new Size(61, 17); // label_zoom.Text = "Zoom:1"; // label_zoom.Click += label_zoom_Click; // // // // label_mouse // // // label_mouse.Name = "label_mouse"; // label_mouse.Size = new Size(65, 17); // label_mouse.Text = "X:0 Y:0"; // // // // toolStripStatusLabel_split1 // // // toolStripStatusLabel_split1.Name = "toolStripStatusLabel_split1"; // toolStripStatusLabel_split1.Size = new Size(11, 17); // toolStripStatusLabel_split1.Text = "|"; // // // // label_ZZ // // // label_ZZ.Name = "label_ZZ"; // label_ZZ.Size = new Size(71, 17); // label_ZZ.Text = "正交模式:开"; // label_ZZ.Click += label_ZZ_Click; // // // // toolStripStatusLabel_split2 // // // toolStripStatusLabel_split2.Name = "toolStripStatusLabel_split2"; // toolStripStatusLabel_split2.Size = new Size(11, 17); // toolStripStatusLabel_split2.Text = "|"; // // // // label_file // // // label_file.Name = "label_file"; // label_file.Size = new Size(25, 17); // label_file.Text = "file"; // label_file.Click += label_file_Click; // label_file.DoubleClick += label_file_DoubleClick; // // // // panel1 // // // panel1.Controls.Add(toolStrip1); // panel1.Dock = DockStyle.Top; // panel1.Location = new Point(0, 0); // panel1.Name = "panel1"; // panel1.Size = new Size(1051, 24); // panel1.TabIndex = 7; // // // // toolStrip1 // // // toolStrip1.Dock = DockStyle.None; // toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripSplitButton2, toolStripButton_save, toolStripSeparator2, toolStripButton_普通, toolStripButton_新建节点, toolStripButton_新建管线, toolStripButton_新建立管, toolStripButton_添加水库, toolStripButton_添加水池, toolStripButton_添加水泵, toolStripButton_添加阀门, toolStripButton_添加水表, toolStripButton_重复器, buttonUndo, buttonRedo, toolStripButton_ClearMinor, toolStripSeparator4, toolStripButton_刷新, btn_水量初分配, toolStripDropDownButton_工具, toolStripSeparator8, toolStripSplitButton1, toolStripComboBox_浏览模式, toolStripDropDownButton1, cb_Node_Colour, cb_Link_Colour, tb_颜色分级设置, toolStripSeparator21 }); // toolStrip1.Location = new Point(0, 0); // toolStrip1.Name = "toolStrip1"; // toolStrip1.Size = new Size(1072, 25); // toolStrip1.TabIndex = 6; // toolStrip1.Text = "toolStrip1"; // // // // toolStripSplitButton2 // // // toolStripSplitButton2.DropDownItems.AddRange(new ToolStripItem[] { 新建ToolStripMenuItem, toolStripSeparator1, 打开文件位置ToolStripMenuItem, ePA中打开ToolStripMenuItem, 旧版打开ToolStripMenuItem }); // toolStripSplitButton2.Image = (System.Drawing.Image)resources.GetObject("toolStripSplitButton2.Image"); // toolStripSplitButton2.ImageTransparentColor = Color.Magenta; // toolStripSplitButton2.Name = "toolStripSplitButton2"; // toolStripSplitButton2.Size = new Size(64, 22); // toolStripSplitButton2.Text = "打开"; // toolStripSplitButton2.ButtonClick += tool打开_ButtonClick; // // // // 新建ToolStripMenuItem // // // 新建ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("新建ToolStripMenuItem.Image"); // 新建ToolStripMenuItem.Name = "新建ToolStripMenuItem"; // 新建ToolStripMenuItem.Size = new Size(148, 22); // 新建ToolStripMenuItem.Text = "新建"; // // // // toolStripSeparator1 // // // toolStripSeparator1.Name = "toolStripSeparator1"; // toolStripSeparator1.Size = new Size(145, 6); // // // // 打开文件位置ToolStripMenuItem // // // 打开文件位置ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("打开文件位置ToolStripMenuItem.Image"); // 打开文件位置ToolStripMenuItem.Name = "打开文件位置ToolStripMenuItem"; // 打开文件位置ToolStripMenuItem.Size = new Size(148, 22); // 打开文件位置ToolStripMenuItem.Text = "打开文件位置"; // 打开文件位置ToolStripMenuItem.Click += 打开文件位置ToolStripMenuItem_Click; // // // // ePA中打开ToolStripMenuItem // // // ePA中打开ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("ePA中打开ToolStripMenuItem.Image"); // ePA中打开ToolStripMenuItem.Name = "ePA中打开ToolStripMenuItem"; // ePA中打开ToolStripMenuItem.Size = new Size(148, 22); // ePA中打开ToolStripMenuItem.Text = "EPA中打开"; // ePA中打开ToolStripMenuItem.Click += EPA中打开ToolStripMenuItem_Click; // // // // 旧版打开ToolStripMenuItem // // // 旧版打开ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("旧版打开ToolStripMenuItem.Image"); // 旧版打开ToolStripMenuItem.Name = "旧版打开ToolStripMenuItem"; // 旧版打开ToolStripMenuItem.Size = new Size(148, 22); // 旧版打开ToolStripMenuItem.Text = "旧版打开"; // 旧版打开ToolStripMenuItem.Visible = false; // 旧版打开ToolStripMenuItem.Click += 旧版打开ToolStripMenuItem_Click; // // // // toolStripButton_save // // // toolStripButton_save.DropDownItems.AddRange(new ToolStripItem[] { 另存为ToolStripMenuItem, 以当前视角另存ToolStripMenuItem, 增量保存ToolStripMenuItem }); // toolStripButton_save.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_save.Image"); // toolStripButton_save.ImageTransparentColor = Color.Magenta; // toolStripButton_save.Name = "toolStripButton_save"; // toolStripButton_save.Size = new Size(64, 22); // toolStripButton_save.Text = "保存"; // toolStripButton_save.ButtonClick += toolStripButton_save_ButtonClick; // // // // 另存为ToolStripMenuItem // // // 另存为ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("另存为ToolStripMenuItem.Image"); // 另存为ToolStripMenuItem.Name = "另存为ToolStripMenuItem"; // 另存为ToolStripMenuItem.Size = new Size(160, 22); // 另存为ToolStripMenuItem.Text = "另存为"; // // // // 以当前视角另存ToolStripMenuItem // // // 以当前视角另存ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("以当前视角另存ToolStripMenuItem.Image"); // 以当前视角另存ToolStripMenuItem.Name = "以当前视角另存ToolStripMenuItem"; // 以当前视角另存ToolStripMenuItem.Size = new Size(160, 22); // 以当前视角另存ToolStripMenuItem.Text = "以当前视角另存"; // 以当前视角另存ToolStripMenuItem.Click += 以当前视角另存ToolStripMenuItem_Click; // // // // 增量保存ToolStripMenuItem // // // 增量保存ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("增量保存ToolStripMenuItem.Image"); // 增量保存ToolStripMenuItem.Name = "增量保存ToolStripMenuItem"; // 增量保存ToolStripMenuItem.Size = new Size(160, 22); // 增量保存ToolStripMenuItem.Text = "增量保存"; // 增量保存ToolStripMenuItem.Click += 增量保存ToolStripMenuItem_Click; // // // // toolStripSeparator2 // // // toolStripSeparator2.Name = "toolStripSeparator2"; // toolStripSeparator2.Size = new Size(6, 25); // // // // toolStripButton_普通 // // // toolStripButton_普通.DisplayStyle = ToolStripItemDisplayStyle.Image; // toolStripButton_普通.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_普通.Image"); // toolStripButton_普通.ImageTransparentColor = Color.Magenta; // toolStripButton_普通.Name = "toolStripButton_普通"; // toolStripButton_普通.Size = new Size(23, 22); // toolStripButton_普通.Text = "选择工具"; // toolStripButton_普通.Click += toolStripButton_普通_Click; // // // // toolStripButton_新建节点 // // // toolStripButton_新建节点.DisplayStyle = ToolStripItemDisplayStyle.Image; // toolStripButton_新建节点.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_新建节点.Image"); // toolStripButton_新建节点.ImageTransparentColor = Color.Magenta; // toolStripButton_新建节点.Name = "toolStripButton_新建节点"; // toolStripButton_新建节点.Size = new Size(23, 22); // toolStripButton_新建节点.Text = "添加节点"; // toolStripButton_新建节点.Click += toolStripButton_新建节点_Click; // // // // toolStripButton_新建管线 // // // toolStripButton_新建管线.DisplayStyle = ToolStripItemDisplayStyle.Image; // toolStripButton_新建管线.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_新建管线.Image"); // toolStripButton_新建管线.ImageTransparentColor = Color.Magenta; // toolStripButton_新建管线.Name = "toolStripButton_新建管线"; // toolStripButton_新建管线.Size = new Size(23, 22); // toolStripButton_新建管线.Text = "添加管线"; // toolStripButton_新建管线.Click += toolStripButton_新建管线_Click; // // // // toolStripButton_新建立管 // // // toolStripButton_新建立管.DisplayStyle = ToolStripItemDisplayStyle.Image; // toolStripButton_新建立管.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_新建立管.Image"); // toolStripButton_新建立管.ImageTransparentColor = Color.Magenta; // toolStripButton_新建立管.Name = "toolStripButton_新建立管"; // toolStripButton_新建立管.Size = new Size(23, 22); // toolStripButton_新建立管.Text = "添加管线"; // toolStripButton_新建立管.Click += toolStripButton_新建立管_Click; // // // // toolStripButton_添加水库 // // // toolStripButton_添加水库.DisplayStyle = ToolStripItemDisplayStyle.Image; // toolStripButton_添加水库.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_添加水库.Image"); // toolStripButton_添加水库.ImageTransparentColor = Color.Magenta; // toolStripButton_添加水库.Name = "toolStripButton_添加水库"; // toolStripButton_添加水库.Size = new Size(23, 22); // toolStripButton_添加水库.Text = "添加水库"; // toolStripButton_添加水库.Click += toolStripButton_添加水库_Click; // // // // toolStripButton_添加水池 // // // toolStripButton_添加水池.DisplayStyle = ToolStripItemDisplayStyle.Image; // toolStripButton_添加水池.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_添加水池.Image"); // toolStripButton_添加水池.ImageTransparentColor = Color.Magenta; // toolStripButton_添加水池.Name = "toolStripButton_添加水池"; // toolStripButton_添加水池.Size = new Size(23, 22); // toolStripButton_添加水池.Text = "添加水池"; // toolStripButton_添加水池.Click += toolStripButton_添加水池_Click; // // // // toolStripButton_添加水泵 // // // toolStripButton_添加水泵.DisplayStyle = ToolStripItemDisplayStyle.Image; // toolStripButton_添加水泵.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_添加水泵.Image"); // toolStripButton_添加水泵.ImageTransparentColor = Color.Magenta; // toolStripButton_添加水泵.Name = "toolStripButton_添加水泵"; // toolStripButton_添加水泵.Size = new Size(23, 22); // toolStripButton_添加水泵.Text = "添加水泵"; // toolStripButton_添加水泵.Click += toolStripButton_添加水泵_Click; // // // // toolStripButton_添加阀门 // // // toolStripButton_添加阀门.DisplayStyle = ToolStripItemDisplayStyle.Image; // toolStripButton_添加阀门.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_添加阀门.Image"); // toolStripButton_添加阀门.ImageTransparentColor = Color.Magenta; // toolStripButton_添加阀门.Name = "toolStripButton_添加阀门"; // toolStripButton_添加阀门.Size = new Size(23, 22); // toolStripButton_添加阀门.Text = "添加阀门"; // toolStripButton_添加阀门.Click += toolStripButton_添加阀门_Click; // // // // toolStripButton_添加水表 // // // toolStripButton_添加水表.DisplayStyle = ToolStripItemDisplayStyle.Image; // toolStripButton_添加水表.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_添加水表.Image"); // toolStripButton_添加水表.ImageTransparentColor = Color.Magenta; // toolStripButton_添加水表.Name = "toolStripButton_添加水表"; // toolStripButton_添加水表.Size = new Size(23, 22); // toolStripButton_添加水表.Text = "添加水表"; // toolStripButton_添加水表.Click += toolStripButton_添加水表_Click; // // // // toolStripButton_重复器 // // // toolStripButton_重复器.DisplayStyle = ToolStripItemDisplayStyle.Image; // toolStripButton_重复器.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_重复器.Image"); // toolStripButton_重复器.ImageTransparentColor = Color.Magenta; // toolStripButton_重复器.Name = "toolStripButton_重复器"; // toolStripButton_重复器.Size = new Size(23, 22); // toolStripButton_重复器.Text = "添加重复器"; // toolStripButton_重复器.Visible = false; // toolStripButton_重复器.Click += toolStripButton_重复器_Click; // // // // buttonUndo // // // buttonUndo.DisplayStyle = ToolStripItemDisplayStyle.Image; // buttonUndo.Image = (System.Drawing.Image)resources.GetObject("buttonUndo.Image"); // buttonUndo.ImageTransparentColor = Color.Magenta; // buttonUndo.Name = "buttonUndo"; // buttonUndo.Size = new Size(23, 22); // buttonUndo.Text = "撤回"; // buttonUndo.Click += buttonUndo_Click; // // // // buttonRedo // // // buttonRedo.DisplayStyle = ToolStripItemDisplayStyle.Image; // buttonRedo.Image = (System.Drawing.Image)resources.GetObject("buttonRedo.Image"); // buttonRedo.ImageTransparentColor = Color.Magenta; // buttonRedo.Name = "buttonRedo"; // buttonRedo.Size = new Size(23, 22); // buttonRedo.Text = "重做"; // buttonRedo.Click += buttonRedo_Click; // // // // toolStripButton_ClearMinor // // // toolStripButton_ClearMinor.DisplayStyle = ToolStripItemDisplayStyle.Image; // toolStripButton_ClearMinor.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_ClearMinor.Image"); // toolStripButton_ClearMinor.ImageTransparentColor = Color.Magenta; // toolStripButton_ClearMinor.Name = "toolStripButton_ClearMinor"; // toolStripButton_ClearMinor.Size = new Size(23, 22); // toolStripButton_ClearMinor.Text = "清空局部损失"; // toolStripButton_ClearMinor.Click += toolStripButton_ClearMinor_Click; // // // // toolStripSeparator4 // // // toolStripSeparator4.Name = "toolStripSeparator4"; // toolStripSeparator4.Size = new Size(6, 25); // // // // toolStripButton_刷新 // // // toolStripButton_刷新.Image = (System.Drawing.Image)resources.GetObject("toolStripButton_刷新.Image"); // toolStripButton_刷新.ImageTransparentColor = Color.Magenta; // toolStripButton_刷新.Name = "toolStripButton_刷新"; // toolStripButton_刷新.Size = new Size(52, 22); // toolStripButton_刷新.Text = "计算"; // toolStripButton_刷新.Click += toolStripButton_计算_Click; // // // // btn_水量初分配 // // // btn_水量初分配.Image = (System.Drawing.Image)resources.GetObject("btn_水量初分配.Image"); // btn_水量初分配.ImageTransparentColor = Color.Magenta; // btn_水量初分配.Name = "btn_水量初分配"; // btn_水量初分配.Size = new Size(76, 22); // btn_水量初分配.Text = "拓扑检查"; // btn_水量初分配.Click += btn_拓扑检查_Click; // // // // toolStripDropDownButton_工具 // // // toolStripDropDownButton_工具.DropDownItems.AddRange(new ToolStripItem[] { 水平旋转ToolStripMenuItem, 轴旋转ToolStripMenuItem, 轴镜像ToolStripMenuItem, 缩放ToolStripMenuItem, toolStripSeparator7, 关阀分析ToolStripMenuItem, 连通性检查ToolStripMenuItem1, 下游连通性ToolStripMenuItem, 上游连通性ToolStripMenuItem, 标高推测ToolStripMenuItem, 标高导出ToolStripMenuItem, 显示水流ToolStripMenuItem, 方向修复ToolStripMenuItem, toolStripSeparator12, 复制ToolStripMenuItem, 粘贴ToolStripMenuItem, 删除ToolStripMenuItem1, toolStripSeparator15, 对齐ToolStripMenuItem, 排列ToolStripMenuItem, toolStripSeparator22, 楼层管理ToolStripMenuItem, 水量分配ToolStripMenuItem, 计算局部损失ToolStripMenuItem }); // toolStripDropDownButton_工具.Image = (System.Drawing.Image)resources.GetObject("toolStripDropDownButton_工具.Image"); // toolStripDropDownButton_工具.ImageTransparentColor = Color.Magenta; // toolStripDropDownButton_工具.Name = "toolStripDropDownButton_工具"; // toolStripDropDownButton_工具.Size = new Size(61, 22); // toolStripDropDownButton_工具.Text = "工具"; // // // // 水平旋转ToolStripMenuItem // // // 水平旋转ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { toolStripTextBox_水平旋转角度 }); // 水平旋转ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("水平旋转ToolStripMenuItem.Image"); // 水平旋转ToolStripMenuItem.Name = "水平旋转ToolStripMenuItem"; // 水平旋转ToolStripMenuItem.Size = new Size(148, 22); // 水平旋转ToolStripMenuItem.Text = "水平旋转"; // 水平旋转ToolStripMenuItem.Click += 水平旋转ToolStripMenuItem_Click; // // // // toolStripTextBox_水平旋转角度 // // // toolStripTextBox_水平旋转角度.Name = "toolStripTextBox_水平旋转角度"; // toolStripTextBox_水平旋转角度.Size = new Size(100, 23); // toolStripTextBox_水平旋转角度.Text = "45"; // // // // 轴旋转ToolStripMenuItem // // // 轴旋转ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("轴旋转ToolStripMenuItem.Image"); // 轴旋转ToolStripMenuItem.Name = "轴旋转ToolStripMenuItem"; // 轴旋转ToolStripMenuItem.Size = new Size(148, 22); // 轴旋转ToolStripMenuItem.Text = "轴旋转"; // // // // 轴镜像ToolStripMenuItem // // // 轴镜像ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("轴镜像ToolStripMenuItem.Image"); // 轴镜像ToolStripMenuItem.Name = "轴镜像ToolStripMenuItem"; // 轴镜像ToolStripMenuItem.Size = new Size(148, 22); // 轴镜像ToolStripMenuItem.Text = "轴镜像"; // // // // 缩放ToolStripMenuItem // // // 缩放ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { toolStripTextBox_缩放比例, toolStripMenuItem_放大2倍, toolStripMenuItem_缩小2倍 }); // 缩放ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("缩放ToolStripMenuItem.Image"); // 缩放ToolStripMenuItem.Name = "缩放ToolStripMenuItem"; // 缩放ToolStripMenuItem.Size = new Size(148, 22); // 缩放ToolStripMenuItem.Text = "缩放"; // 缩放ToolStripMenuItem.Click += 缩放ToolStripMenuItem_Click; // // // // toolStripTextBox_缩放比例 // // // toolStripTextBox_缩放比例.Name = "toolStripTextBox_缩放比例"; // toolStripTextBox_缩放比例.Size = new Size(100, 23); // toolStripTextBox_缩放比例.Text = "0.5"; // // // // toolStripMenuItem_放大2倍 // // // toolStripMenuItem_放大2倍.Name = "toolStripMenuItem_放大2倍"; // toolStripMenuItem_放大2倍.Size = new Size(160, 22); // toolStripMenuItem_放大2倍.Text = "放大2倍"; // toolStripMenuItem_放大2倍.Click += 缩放ToolStripMenuItem_Click; // // // // toolStripMenuItem_缩小2倍 // // // toolStripMenuItem_缩小2倍.Name = "toolStripMenuItem_缩小2倍"; // toolStripMenuItem_缩小2倍.Size = new Size(160, 22); // toolStripMenuItem_缩小2倍.Text = "缩小2倍"; // toolStripMenuItem_缩小2倍.Click += 缩放ToolStripMenuItem_Click; // // // // toolStripSeparator7 // // // toolStripSeparator7.Name = "toolStripSeparator7"; // toolStripSeparator7.Size = new Size(145, 6); // // // // 关阀分析ToolStripMenuItem // // // 关阀分析ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { 关阀分析不考虑水源ToolStripMenuItem }); // 关阀分析ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("关阀分析ToolStripMenuItem.Image"); // 关阀分析ToolStripMenuItem.Name = "关阀分析ToolStripMenuItem"; // 关阀分析ToolStripMenuItem.Size = new Size(148, 22); // 关阀分析ToolStripMenuItem.Text = "关阀分析"; // 关阀分析ToolStripMenuItem.Click += 关阀搜索考虑水源ToolStripMenuItem_Click; // // // // 关阀分析不考虑水源ToolStripMenuItem // // // 关阀分析不考虑水源ToolStripMenuItem.Name = "关阀分析不考虑水源ToolStripMenuItem"; // 关阀分析不考虑水源ToolStripMenuItem.Size = new Size(208, 22); // 关阀分析不考虑水源ToolStripMenuItem.Text = "关阀分析(不考虑水源)"; // 关阀分析不考虑水源ToolStripMenuItem.Click += 关阀搜索ToolStripMenuItem_Click; // // // // 连通性检查ToolStripMenuItem1 // // // 连通性检查ToolStripMenuItem1.Image = (System.Drawing.Image)resources.GetObject("连通性检查ToolStripMenuItem1.Image"); // 连通性检查ToolStripMenuItem1.Name = "连通性检查ToolStripMenuItem1"; // 连通性检查ToolStripMenuItem1.Size = new Size(148, 22); // 连通性检查ToolStripMenuItem1.Text = "连通性检查"; // 连通性检查ToolStripMenuItem1.Click += 连通性检查ToolStripMenuItem1_Click; // // // // 下游连通性ToolStripMenuItem // // // 下游连通性ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("下游连通性ToolStripMenuItem.Image"); // 下游连通性ToolStripMenuItem.Name = "下游连通性ToolStripMenuItem"; // 下游连通性ToolStripMenuItem.Size = new Size(148, 22); // 下游连通性ToolStripMenuItem.Text = "下游连通性"; // 下游连通性ToolStripMenuItem.Click += 下游连通性ToolStripMenuItem_Click; // // // // 上游连通性ToolStripMenuItem // // // 上游连通性ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("上游连通性ToolStripMenuItem.Image"); // 上游连通性ToolStripMenuItem.Name = "上游连通性ToolStripMenuItem"; // 上游连通性ToolStripMenuItem.Size = new Size(148, 22); // 上游连通性ToolStripMenuItem.Text = "上游连通性"; // // // // 标高推测ToolStripMenuItem // // // 标高推测ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("标高推测ToolStripMenuItem.Image"); // 标高推测ToolStripMenuItem.Name = "标高推测ToolStripMenuItem"; // 标高推测ToolStripMenuItem.Size = new Size(148, 22); // 标高推测ToolStripMenuItem.Text = "标高推测"; // 标高推测ToolStripMenuItem.Click += 标高推测ToolStripMenuItem_Click; // // // // 标高导出ToolStripMenuItem // // // 标高导出ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("标高导出ToolStripMenuItem.Image"); // 标高导出ToolStripMenuItem.Name = "标高导出ToolStripMenuItem"; // 标高导出ToolStripMenuItem.Size = new Size(148, 22); // 标高导出ToolStripMenuItem.Text = "标高导出"; // 标高导出ToolStripMenuItem.Click += 标高导出ToolStripMenuItem_Click; // // // // 显示水流ToolStripMenuItem // // // 显示水流ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("显示水流ToolStripMenuItem.Image"); // 显示水流ToolStripMenuItem.Name = "显示水流ToolStripMenuItem"; // 显示水流ToolStripMenuItem.Size = new Size(148, 22); // 显示水流ToolStripMenuItem.Text = "显示水流路线"; // 显示水流ToolStripMenuItem.Click += 显示水流ToolStripMenuItem_Click; // // // // 方向修复ToolStripMenuItem // // // 方向修复ToolStripMenuItem.Name = "方向修复ToolStripMenuItem"; // 方向修复ToolStripMenuItem.Size = new Size(148, 22); // 方向修复ToolStripMenuItem.Text = "方向修复"; // 方向修复ToolStripMenuItem.Click += 方向修复ToolStripMenuItem_Click; // // // // toolStripSeparator12 // // // toolStripSeparator12.Name = "toolStripSeparator12"; // toolStripSeparator12.Size = new Size(145, 6); // // // // 复制ToolStripMenuItem // // // 复制ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("复制ToolStripMenuItem.Image"); // 复制ToolStripMenuItem.Name = "复制ToolStripMenuItem"; // 复制ToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+C"; // 复制ToolStripMenuItem.Size = new Size(148, 22); // 复制ToolStripMenuItem.Text = "复制"; // 复制ToolStripMenuItem.Click += 复制ToolStripMenuItem_Click; // // // // 粘贴ToolStripMenuItem // // // 粘贴ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("粘贴ToolStripMenuItem.Image"); // 粘贴ToolStripMenuItem.Name = "粘贴ToolStripMenuItem"; // 粘贴ToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+V"; // 粘贴ToolStripMenuItem.Size = new Size(148, 22); // 粘贴ToolStripMenuItem.Text = "粘贴"; // 粘贴ToolStripMenuItem.Click += 粘贴ToolStripMenuItem1_Click; // // // // 删除ToolStripMenuItem1 // // // 删除ToolStripMenuItem1.Name = "删除ToolStripMenuItem1"; // 删除ToolStripMenuItem1.Size = new Size(148, 22); // 删除ToolStripMenuItem1.Text = "删除"; // 删除ToolStripMenuItem1.Click += 删除ToolStripMenuItem_Click; // // // // toolStripSeparator15 // // // toolStripSeparator15.Name = "toolStripSeparator15"; // toolStripSeparator15.Size = new Size(145, 6); // // // // 对齐ToolStripMenuItem // // // 对齐ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { toolStripSeparator16, 东西对齐ToolStripMenuItem, 南北对齐ToolStripMenuItem, 竖直对齐ToolStripMenuItem, 自动对齐ToolStripMenuItem }); // 对齐ToolStripMenuItem.Name = "对齐ToolStripMenuItem"; // 对齐ToolStripMenuItem.Size = new Size(148, 22); // 对齐ToolStripMenuItem.Text = "对齐"; // // // // toolStripSeparator16 // // // toolStripSeparator16.Name = "toolStripSeparator16"; // toolStripSeparator16.Size = new Size(167, 6); // // // // 东西对齐ToolStripMenuItem // // // 东西对齐ToolStripMenuItem.Name = "东西对齐ToolStripMenuItem"; // 东西对齐ToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+1"; // 东西对齐ToolStripMenuItem.Size = new Size(170, 22); // 东西对齐ToolStripMenuItem.Text = "东西对齐"; // 东西对齐ToolStripMenuItem.Click += 东西对齐ToolStripMenuItem_Click; // // // // 南北对齐ToolStripMenuItem // // // 南北对齐ToolStripMenuItem.Name = "南北对齐ToolStripMenuItem"; // 南北对齐ToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+~"; // 南北对齐ToolStripMenuItem.Size = new Size(170, 22); // 南北对齐ToolStripMenuItem.Text = "南北对齐"; // 南北对齐ToolStripMenuItem.Click += 南北对齐ToolStripMenuItem_Click; // // // // 竖直对齐ToolStripMenuItem // // // 竖直对齐ToolStripMenuItem.Name = "竖直对齐ToolStripMenuItem"; // 竖直对齐ToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+2"; // 竖直对齐ToolStripMenuItem.Size = new Size(170, 22); // 竖直对齐ToolStripMenuItem.Text = "竖直对齐"; // 竖直对齐ToolStripMenuItem.Click += 竖直对齐ToolStripMenuItem_Click; // // // // 自动对齐ToolStripMenuItem // // // 自动对齐ToolStripMenuItem.Name = "自动对齐ToolStripMenuItem"; // 自动对齐ToolStripMenuItem.ShortcutKeyDisplayString = "Ctrl+3"; // 自动对齐ToolStripMenuItem.Size = new Size(170, 22); // 自动对齐ToolStripMenuItem.Text = "自动对齐"; // 自动对齐ToolStripMenuItem.Click += 自动对齐ToolStripMenuItem_Click; // // // // 排列ToolStripMenuItem // // // 排列ToolStripMenuItem.Name = "排列ToolStripMenuItem"; // 排列ToolStripMenuItem.Size = new Size(148, 22); // 排列ToolStripMenuItem.Text = "排列"; // // // // toolStripSeparator22 // // // toolStripSeparator22.Name = "toolStripSeparator22"; // toolStripSeparator22.Size = new Size(145, 6); // // // // 楼层管理ToolStripMenuItem // // // 楼层管理ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("楼层管理ToolStripMenuItem.Image"); // 楼层管理ToolStripMenuItem.Name = "楼层管理ToolStripMenuItem"; // 楼层管理ToolStripMenuItem.Size = new Size(148, 22); // 楼层管理ToolStripMenuItem.Text = "楼层管理"; // 楼层管理ToolStripMenuItem.Click += 楼层管理ToolStripMenuItem_Click; // // // // 水量分配ToolStripMenuItem // // // 水量分配ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("水量分配ToolStripMenuItem.Image"); // 水量分配ToolStripMenuItem.Name = "水量分配ToolStripMenuItem"; // 水量分配ToolStripMenuItem.Size = new Size(148, 22); // 水量分配ToolStripMenuItem.Text = "水量分配"; // // // // 计算局部损失ToolStripMenuItem // // // 计算局部损失ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("计算局部损失ToolStripMenuItem.Image"); // 计算局部损失ToolStripMenuItem.Name = "计算局部损失ToolStripMenuItem"; // 计算局部损失ToolStripMenuItem.Size = new Size(148, 22); // 计算局部损失ToolStripMenuItem.Text = "计算局部损失"; // 计算局部损失ToolStripMenuItem.Click += toolStripButton_CalcMiniLoss_Click; // // // // toolStripSeparator8 // // // toolStripSeparator8.Name = "toolStripSeparator8"; // toolStripSeparator8.Size = new Size(6, 25); // // // // toolStripSplitButton1 // // // toolStripSplitButton1.DropDownItems.AddRange(new ToolStripItem[] { 重置ToolStripMenuItem, toolStripSeparator14, toolStripMenuItem8, toolStripMenuItem7, toolStripMenuItem6, toolStripMenuItem5, toolStripMenuItem4, toolStripMenuItem3, toolStripMenuItem2, toolStripSeparator3, ToolStripMenuItem_Floor, 显示全部楼层ToolStripMenuItem, 保存楼层视角ToolStripMenuItem, 刷新楼层ToolStripMenuItem }); // toolStripSplitButton1.Image = (System.Drawing.Image)resources.GetObject("toolStripSplitButton1.Image"); // toolStripSplitButton1.ImageTransparentColor = Color.Magenta; // toolStripSplitButton1.Name = "toolStripSplitButton1"; // toolStripSplitButton1.Size = new Size(64, 22); // toolStripSplitButton1.Text = "视角"; // toolStripSplitButton1.ButtonClick += tool视角_ButtonClick; // // // // 重置ToolStripMenuItem // // // 重置ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("重置ToolStripMenuItem.Image"); // 重置ToolStripMenuItem.Name = "重置ToolStripMenuItem"; // 重置ToolStripMenuItem.Size = new Size(148, 22); // 重置ToolStripMenuItem.Text = "重置"; // 重置ToolStripMenuItem.Click += 重置视角ToolStripMenuItem_Click; // // // // toolStripSeparator14 // // // toolStripSeparator14.Name = "toolStripSeparator14"; // toolStripSeparator14.Size = new Size(145, 6); // // // // toolStripMenuItem8 // // // toolStripMenuItem8.Image = (System.Drawing.Image)resources.GetObject("toolStripMenuItem8.Image"); // toolStripMenuItem8.Name = "toolStripMenuItem8"; // toolStripMenuItem8.Size = new Size(148, 22); // toolStripMenuItem8.Text = "90"; // toolStripMenuItem8.Click += tool设置俯视角度_Click; // // // // toolStripMenuItem7 // // // toolStripMenuItem7.Name = "toolStripMenuItem7"; // toolStripMenuItem7.Size = new Size(148, 22); // toolStripMenuItem7.Text = "75"; // toolStripMenuItem7.Click += tool设置俯视角度_Click; // // // // toolStripMenuItem6 // // // toolStripMenuItem6.Name = "toolStripMenuItem6"; // toolStripMenuItem6.Size = new Size(148, 22); // toolStripMenuItem6.Text = "60"; // toolStripMenuItem6.Click += tool设置俯视角度_Click; // // // // toolStripMenuItem5 // // // toolStripMenuItem5.Name = "toolStripMenuItem5"; // toolStripMenuItem5.Size = new Size(148, 22); // toolStripMenuItem5.Text = "45"; // toolStripMenuItem5.Click += tool设置俯视角度_Click; // // // // toolStripMenuItem4 // // // toolStripMenuItem4.Name = "toolStripMenuItem4"; // toolStripMenuItem4.Size = new Size(148, 22); // toolStripMenuItem4.Text = "30"; // toolStripMenuItem4.Click += tool设置俯视角度_Click; // // // // toolStripMenuItem3 // // // toolStripMenuItem3.Name = "toolStripMenuItem3"; // toolStripMenuItem3.Size = new Size(148, 22); // toolStripMenuItem3.Text = "15"; // toolStripMenuItem3.Click += tool设置俯视角度_Click; // // // // toolStripMenuItem2 // // // toolStripMenuItem2.Image = (System.Drawing.Image)resources.GetObject("toolStripMenuItem2.Image"); // toolStripMenuItem2.Name = "toolStripMenuItem2"; // toolStripMenuItem2.Size = new Size(148, 22); // toolStripMenuItem2.Text = "0"; // toolStripMenuItem2.Click += tool设置俯视角度_Click; // // // // toolStripSeparator3 // // // toolStripSeparator3.Name = "toolStripSeparator3"; // toolStripSeparator3.Size = new Size(145, 6); // // // // ToolStripMenuItem_Floor // // // ToolStripMenuItem_Floor.Name = "ToolStripMenuItem_Floor"; // ToolStripMenuItem_Floor.Size = new Size(148, 22); // ToolStripMenuItem_Floor.Text = "楼层"; // // // // 显示全部楼层ToolStripMenuItem // // // 显示全部楼层ToolStripMenuItem.Name = "显示全部楼层ToolStripMenuItem"; // 显示全部楼层ToolStripMenuItem.Size = new Size(148, 22); // 显示全部楼层ToolStripMenuItem.Text = "显示全部楼层"; // 显示全部楼层ToolStripMenuItem.Click += 显示全部楼层ToolStripMenuItem_Click; // // // // 保存楼层视角ToolStripMenuItem // // // 保存楼层视角ToolStripMenuItem.Name = "保存楼层视角ToolStripMenuItem"; // 保存楼层视角ToolStripMenuItem.Size = new Size(148, 22); // 保存楼层视角ToolStripMenuItem.Text = "保存楼层视角"; // 保存楼层视角ToolStripMenuItem.Click += 保存楼层视角ToolStripMenuItem_Click; // // // // 刷新楼层ToolStripMenuItem // // // 刷新楼层ToolStripMenuItem.Name = "刷新楼层ToolStripMenuItem"; // 刷新楼层ToolStripMenuItem.Size = new Size(148, 22); // 刷新楼层ToolStripMenuItem.Text = "刷新楼层"; // 刷新楼层ToolStripMenuItem.Click += 刷新楼层ToolStripMenuItem_Click; // // // // toolStripComboBox_浏览模式 // // // toolStripComboBox_浏览模式.DropDownItems.AddRange(new ToolStripItem[] { 浏览模式ToolStripMenuItem, 编辑模式ToolStripMenuItem }); // toolStripComboBox_浏览模式.Image = (System.Drawing.Image)resources.GetObject("toolStripComboBox_浏览模式.Image"); // toolStripComboBox_浏览模式.Name = "toolStripComboBox_浏览模式"; // toolStripComboBox_浏览模式.Size = new Size(88, 22); // toolStripComboBox_浏览模式.Text = "编辑模式"; // toolStripComboBox_浏览模式.ButtonClick += toolStripComboBox_expandRepeater_ButtonClick; // // // // 浏览模式ToolStripMenuItem // // // 浏览模式ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("浏览模式ToolStripMenuItem.Image"); // 浏览模式ToolStripMenuItem.Name = "浏览模式ToolStripMenuItem"; // 浏览模式ToolStripMenuItem.Size = new Size(124, 22); // 浏览模式ToolStripMenuItem.Text = "浏览模式"; // 浏览模式ToolStripMenuItem.Click += 浏览模式ToolStripMenuItem_Click; // // // // 编辑模式ToolStripMenuItem // // // 编辑模式ToolStripMenuItem.Image = (System.Drawing.Image)resources.GetObject("编辑模式ToolStripMenuItem.Image"); // 编辑模式ToolStripMenuItem.Name = "编辑模式ToolStripMenuItem"; // 编辑模式ToolStripMenuItem.Size = new Size(124, 22); // 编辑模式ToolStripMenuItem.Text = "编辑模式"; // 编辑模式ToolStripMenuItem.Click += 浏览模式ToolStripMenuItem_Click; // // // // toolStripDropDownButton1 // // // toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { 显示节点ToolStripMenuItem, 隐藏节点ToolStripMenuItem, 节点大小ToolStripMenuItem, toolStripSeparator10, 显示阀门ToolStripMenuItem, 隐藏阀门ToolStripMenuItem, 管线粗细ToolStripMenuItem, toolStripSeparator13, 缩放级别ToolStripMenuItem, toolStripSeparator5, 隐藏内容ToolStripMenuItem, toolStripSeparator17, 添加底图ToolStripMenuItem, 设置底图ToolStripMenuItem, 显示隐藏底图ToolStripMenuItem, 清除底图ToolStripMenuItem, toolStripSeparator18, 显示状态ToolStripMenuItem, 隐藏状态ToolStripMenuItem, toolStripSeparator19, 显示流向ToolStripMenuItem, 隐藏流向ToolStripMenuItem, toolStripSeparator20, 颜色分级管理ToolStripMenuItem }); // toolStripDropDownButton1.Image = (System.Drawing.Image)resources.GetObject("toolStripDropDownButton1.Image"); // toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; // toolStripDropDownButton1.Name = "toolStripDropDownButton1"; // toolStripDropDownButton1.Size = new Size(85, 22); // toolStripDropDownButton1.Text = "显示选项"; // // // // 显示节点ToolStripMenuItem // // // 显示节点ToolStripMenuItem.Name = "显示节点ToolStripMenuItem"; // 显示节点ToolStripMenuItem.Size = new Size(153, 22); // 显示节点ToolStripMenuItem.Text = "显示节点"; // 显示节点ToolStripMenuItem.Click += 显示节点ToolStripMenuItem_Click; // // // // 隐藏节点ToolStripMenuItem // // // 隐藏节点ToolStripMenuItem.Name = "隐藏节点ToolStripMenuItem"; // 隐藏节点ToolStripMenuItem.Size = new Size(153, 22); // 隐藏节点ToolStripMenuItem.Text = "隐藏节点"; // 隐藏节点ToolStripMenuItem.Click += 隐藏节点ToolStripMenuItem_Click; // // // // 节点大小ToolStripMenuItem // // // 节点大小ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { 大ToolStripMenuItem, 中ToolStripMenuItem, 小ToolStripMenuItem }); // 节点大小ToolStripMenuItem.Name = "节点大小ToolStripMenuItem"; // 节点大小ToolStripMenuItem.Size = new Size(153, 22); // 节点大小ToolStripMenuItem.Text = "节点大小"; // // // // 大ToolStripMenuItem // // // 大ToolStripMenuItem.Name = "大ToolStripMenuItem"; // 大ToolStripMenuItem.Size = new Size(88, 22); // 大ToolStripMenuItem.Text = "大"; // 大ToolStripMenuItem.Click += 大ToolStripMenuItem_Click; // // // // 中ToolStripMenuItem // // // 中ToolStripMenuItem.Name = "中ToolStripMenuItem"; // 中ToolStripMenuItem.Size = new Size(88, 22); // 中ToolStripMenuItem.Text = "中"; // 中ToolStripMenuItem.Click += 大ToolStripMenuItem_Click; // // // // 小ToolStripMenuItem // // // 小ToolStripMenuItem.Name = "小ToolStripMenuItem"; // 小ToolStripMenuItem.Size = new Size(88, 22); // 小ToolStripMenuItem.Text = "小"; // 小ToolStripMenuItem.Click += 大ToolStripMenuItem_Click; // // // // toolStripSeparator10 // // // toolStripSeparator10.Name = "toolStripSeparator10"; // toolStripSeparator10.Size = new Size(150, 6); // // // // 显示阀门ToolStripMenuItem // // // 显示阀门ToolStripMenuItem.Name = "显示阀门ToolStripMenuItem"; // 显示阀门ToolStripMenuItem.Size = new Size(153, 22); // 显示阀门ToolStripMenuItem.Text = "显示阀门"; // 显示阀门ToolStripMenuItem.Click += 显示阀门ToolStripMenuItem_Click; // // // // 隐藏阀门ToolStripMenuItem // // // 隐藏阀门ToolStripMenuItem.Name = "隐藏阀门ToolStripMenuItem"; // 隐藏阀门ToolStripMenuItem.Size = new Size(153, 22); // 隐藏阀门ToolStripMenuItem.Text = "隐藏阀门"; // 隐藏阀门ToolStripMenuItem.Click += 隐藏阀门ToolStripMenuItem_Click; // // // // 管线粗细ToolStripMenuItem // // // 管线粗细ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { 大ToolStripMenuItem1, 中ToolStripMenuItem1, 小ToolStripMenuItem1 }); // 管线粗细ToolStripMenuItem.Name = "管线粗细ToolStripMenuItem"; // 管线粗细ToolStripMenuItem.Size = new Size(153, 22); // 管线粗细ToolStripMenuItem.Text = "管线粗细"; // // // // 大ToolStripMenuItem1 // // // 大ToolStripMenuItem1.Name = "大ToolStripMenuItem1"; // 大ToolStripMenuItem1.Size = new Size(88, 22); // 大ToolStripMenuItem1.Text = "大"; // 大ToolStripMenuItem1.Click += 大ToolStripMenuItem1_Click; // // // // 中ToolStripMenuItem1 // // // 中ToolStripMenuItem1.Name = "中ToolStripMenuItem1"; // 中ToolStripMenuItem1.Size = new Size(88, 22); // 中ToolStripMenuItem1.Text = "中"; // 中ToolStripMenuItem1.Click += 大ToolStripMenuItem1_Click; // // // // 小ToolStripMenuItem1 // // // 小ToolStripMenuItem1.Name = "小ToolStripMenuItem1"; // 小ToolStripMenuItem1.Size = new Size(88, 22); // 小ToolStripMenuItem1.Text = "小"; // 小ToolStripMenuItem1.Click += 大ToolStripMenuItem1_Click; // // // // toolStripSeparator13 // // // toolStripSeparator13.Name = "toolStripSeparator13"; // toolStripSeparator13.Size = new Size(150, 6); // // // // 缩放级别ToolStripMenuItem // // // 缩放级别ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { 放大ToolStripMenuItem2, 正常ToolStripMenuItem, 缩小ToolStripMenuItem }); // 缩放级别ToolStripMenuItem.Name = "缩放级别ToolStripMenuItem"; // 缩放级别ToolStripMenuItem.Size = new Size(153, 22); // 缩放级别ToolStripMenuItem.Text = "缩放级别"; // // // // 放大ToolStripMenuItem2 // // // 放大ToolStripMenuItem2.Name = "放大ToolStripMenuItem2"; // 放大ToolStripMenuItem2.Size = new Size(100, 22); // 放大ToolStripMenuItem2.Text = "放大"; // // // // 正常ToolStripMenuItem // // // 正常ToolStripMenuItem.Name = "正常ToolStripMenuItem"; // 正常ToolStripMenuItem.Size = new Size(100, 22); // 正常ToolStripMenuItem.Text = "正常"; // // // // 缩小ToolStripMenuItem // // // 缩小ToolStripMenuItem.Name = "缩小ToolStripMenuItem"; // 缩小ToolStripMenuItem.Size = new Size(100, 22); // 缩小ToolStripMenuItem.Text = "缩小"; // // // // toolStripSeparator5 // // // toolStripSeparator5.Name = "toolStripSeparator5"; // toolStripSeparator5.Size = new Size(150, 6); // // // // 隐藏内容ToolStripMenuItem // // // 隐藏内容ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { 显示所有隐藏内容ToolStripMenuItem, 隐藏ToolStripMenuItem }); // 隐藏内容ToolStripMenuItem.Name = "隐藏内容ToolStripMenuItem"; // 隐藏内容ToolStripMenuItem.Size = new Size(153, 22); // 隐藏内容ToolStripMenuItem.Text = "隐藏内容"; // // // // 显示所有隐藏内容ToolStripMenuItem // // // 显示所有隐藏内容ToolStripMenuItem.Name = "显示所有隐藏内容ToolStripMenuItem"; // 显示所有隐藏内容ToolStripMenuItem.Size = new Size(172, 22); // 显示所有隐藏内容ToolStripMenuItem.Text = "显示所有隐藏内容"; // 显示所有隐藏内容ToolStripMenuItem.Click += 显示所有隐藏内容ToolStripMenuItem_Click; // // // // 隐藏ToolStripMenuItem // // // 隐藏ToolStripMenuItem.Name = "隐藏ToolStripMenuItem"; // 隐藏ToolStripMenuItem.Size = new Size(172, 22); // 隐藏ToolStripMenuItem.Text = "隐藏"; // // // // toolStripSeparator17 // // // toolStripSeparator17.Name = "toolStripSeparator17"; // toolStripSeparator17.Size = new Size(150, 6); // // // // 添加底图ToolStripMenuItem // // // 添加底图ToolStripMenuItem.Name = "添加底图ToolStripMenuItem"; // 添加底图ToolStripMenuItem.Size = new Size(153, 22); // 添加底图ToolStripMenuItem.Text = "添加底图"; // 添加底图ToolStripMenuItem.Click += 添加底图ToolStripMenuItem_Click; // // // // 设置底图ToolStripMenuItem // // // 设置底图ToolStripMenuItem.Name = "设置底图ToolStripMenuItem"; // 设置底图ToolStripMenuItem.Size = new Size(153, 22); // 设置底图ToolStripMenuItem.Text = "设置底图"; // 设置底图ToolStripMenuItem.Click += 设置底图ToolStripMenuItem_Click; // // // // 显示隐藏底图ToolStripMenuItem // // // 显示隐藏底图ToolStripMenuItem.Name = "显示隐藏底图ToolStripMenuItem"; // 显示隐藏底图ToolStripMenuItem.Size = new Size(153, 22); // 显示隐藏底图ToolStripMenuItem.Text = "显示/隐藏底图"; // 显示隐藏底图ToolStripMenuItem.Click += 显示隐藏底图ToolStripMenuItem_Click; // // // // 清除底图ToolStripMenuItem // // // 清除底图ToolStripMenuItem.Name = "清除底图ToolStripMenuItem"; // 清除底图ToolStripMenuItem.Size = new Size(153, 22); // 清除底图ToolStripMenuItem.Text = "清除底图"; // 清除底图ToolStripMenuItem.Click += 清除底图ToolStripMenuItem_Click; // // // // toolStripSeparator18 // // // toolStripSeparator18.Name = "toolStripSeparator18"; // toolStripSeparator18.Size = new Size(150, 6); // // // // 显示状态ToolStripMenuItem // // // 显示状态ToolStripMenuItem.Name = "显示状态ToolStripMenuItem"; // 显示状态ToolStripMenuItem.Size = new Size(153, 22); // 显示状态ToolStripMenuItem.Text = "显示状态"; // 显示状态ToolStripMenuItem.Click += 显示状态ToolStripMenuItem_Click; // // // // 隐藏状态ToolStripMenuItem // // // 隐藏状态ToolStripMenuItem.Name = "隐藏状态ToolStripMenuItem"; // 隐藏状态ToolStripMenuItem.Size = new Size(153, 22); // 隐藏状态ToolStripMenuItem.Text = "隐藏状态"; // 隐藏状态ToolStripMenuItem.Click += 隐藏状态ToolStripMenuItem_Click; // // // // toolStripSeparator19 // // // toolStripSeparator19.Name = "toolStripSeparator19"; // toolStripSeparator19.Size = new Size(150, 6); // // // // 显示流向ToolStripMenuItem // // // 显示流向ToolStripMenuItem.Name = "显示流向ToolStripMenuItem"; // 显示流向ToolStripMenuItem.Size = new Size(153, 22); // 显示流向ToolStripMenuItem.Text = "显示流向"; // 显示流向ToolStripMenuItem.Click += 显示流向ToolStripMenuItem_Click; // // // // 隐藏流向ToolStripMenuItem // // // 隐藏流向ToolStripMenuItem.Name = "隐藏流向ToolStripMenuItem"; // 隐藏流向ToolStripMenuItem.Size = new Size(153, 22); // 隐藏流向ToolStripMenuItem.Text = "隐藏流向"; // 隐藏流向ToolStripMenuItem.Click += 隐藏流向ToolStripMenuItem_Click; // // // // toolStripSeparator20 // // // toolStripSeparator20.Name = "toolStripSeparator20"; // toolStripSeparator20.Size = new Size(150, 6); // // // // 颜色分级管理ToolStripMenuItem // // // 颜色分级管理ToolStripMenuItem.Name = "颜色分级管理ToolStripMenuItem"; // 颜色分级管理ToolStripMenuItem.Size = new Size(153, 22); // 颜色分级管理ToolStripMenuItem.Text = "颜色分级管理"; // 颜色分级管理ToolStripMenuItem.Click += 颜色分级管理ToolStripMenuItem_Click; // // // // cb_Node_Colour // // // cb_Node_Colour.DropDownStyle = ComboBoxStyle.DropDownList; // cb_Node_Colour.DropDownWidth = 75; // cb_Node_Colour.FlatStyle = FlatStyle.Flat; // cb_Node_Colour.Name = "cb_Node_Colour"; // cb_Node_Colour.Size = new Size(75, 25); // cb_Node_Colour.SelectedIndexChanged += cb_Node_Colour_SelectedIndexChanged; // // // // cb_Link_Colour // // // cb_Link_Colour.DropDownStyle = ComboBoxStyle.DropDownList; // cb_Link_Colour.DropDownWidth = 75; // cb_Link_Colour.FlatStyle = FlatStyle.Flat; // cb_Link_Colour.Name = "cb_Link_Colour"; // cb_Link_Colour.Size = new Size(75, 25); // cb_Link_Colour.SelectedIndexChanged += cb_Link_Colour_SelectedIndexChanged; // // // // tb_颜色分级设置 // // // tb_颜色分级设置.Image = (System.Drawing.Image)resources.GetObject("tb_颜色分级设置.Image"); // tb_颜色分级设置.ImageTransparentColor = Color.Magenta; // tb_颜色分级设置.Name = "tb_颜色分级设置"; // tb_颜色分级设置.Size = new Size(52, 22); // tb_颜色分级设置.Text = "分级"; // tb_颜色分级设置.Click += 颜色分级管理ToolStripMenuItem_Click; // // // // toolStripSeparator21 // // // toolStripSeparator21.Name = "toolStripSeparator21"; // toolStripSeparator21.Size = new Size(6, 25); // // // // 右键_Menu // // // 右键_Menu.Items.AddRange(new ToolStripItem[] { 视角ToolStripMenuItem, 对齐ToolStripMenuItem1, toolStripSeparator6, 设置长度ToolStripMenuItem, 设为关闭ToolStripMenuItem, 设为立管点ToolStripMenuItem, 设为隐藏ToolStripMenuItem, 显示ToolStripMenuItem, toolStripSeparator11, 复制ToolStripMenuItem1, 粘贴ToolStripMenuItem1, 转换为ToolStripMenuItem, 删除ToolStripMenuItem, toolStripSeparator9, 全选ToolStripMenuItem, 反选ToolStripMenuItem }); // 右键_Menu.Name = "contextMenuStrip1"; // 右键_Menu.Size = new Size(146, 308); // // // // 视角ToolStripMenuItem // // // 视角ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { 默认视角ToolStripMenuItem, toolStripSeparator23, 俯视图ToolStripMenuItem, 正视图ToolStripMenuItem, 重置视角ToolStripMenuItem }); // 视角ToolStripMenuItem.Name = "视角ToolStripMenuItem"; // 视角ToolStripMenuItem.Size = new Size(145, 22); // 视角ToolStripMenuItem.Text = "视角"; // // // // 默认视角ToolStripMenuItem // // // 默认视角ToolStripMenuItem.Name = "默认视角ToolStripMenuItem"; // 默认视角ToolStripMenuItem.Size = new Size(124, 22); // 默认视角ToolStripMenuItem.Text = "默认视角"; // 默认视角ToolStripMenuItem.Click += 默认视角ToolStripMenuItem_Click; // // // // toolStripSeparator23 // // // toolStripSeparator23.Name = "toolStripSeparator23"; // toolStripSeparator23.Size = new Size(121, 6); // // // // 俯视图ToolStripMenuItem // // // 俯视图ToolStripMenuItem.Name = "俯视图ToolStripMenuItem"; // 俯视图ToolStripMenuItem.Size = new Size(124, 22); // 俯视图ToolStripMenuItem.Text = "俯视图"; // 俯视图ToolStripMenuItem.Click += 俯视图ToolStripMenuItem_Click; // // // // 正视图ToolStripMenuItem // // // 正视图ToolStripMenuItem.Name = "正视图ToolStripMenuItem"; // 正视图ToolStripMenuItem.Size = new Size(124, 22); // 正视图ToolStripMenuItem.Text = "正视图"; // 正视图ToolStripMenuItem.Click += 正视图ToolStripMenuItem_Click; // // // // 重置视角ToolStripMenuItem // // // 重置视角ToolStripMenuItem.Name = "重置视角ToolStripMenuItem"; // 重置视角ToolStripMenuItem.Size = new Size(124, 22); // 重置视角ToolStripMenuItem.Text = "重置视角"; // 重置视角ToolStripMenuItem.Click += 重置视角ToolStripMenuItem_Click; // // // // 对齐ToolStripMenuItem1 // // // 对齐ToolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { 东西对齐ToolStripMenuItem1, 南北对齐ToolStripMenuItem1, 竖直对齐ToolStripMenuItem1, 自动对齐ToolStripMenuItem1 }); // 对齐ToolStripMenuItem1.Name = "对齐ToolStripMenuItem1"; // 对齐ToolStripMenuItem1.Size = new Size(145, 22); // 对齐ToolStripMenuItem1.Text = "对齐"; // // // // 东西对齐ToolStripMenuItem1 // // // 东西对齐ToolStripMenuItem1.Name = "东西对齐ToolStripMenuItem1"; // 东西对齐ToolStripMenuItem1.ShortcutKeyDisplayString = "Ctrl+~"; // 东西对齐ToolStripMenuItem1.Size = new Size(170, 22); // 东西对齐ToolStripMenuItem1.Text = "东西对齐"; // 东西对齐ToolStripMenuItem1.Click += 东西对齐ToolStripMenuItem_Click; // // // // 南北对齐ToolStripMenuItem1 // // // 南北对齐ToolStripMenuItem1.Name = "南北对齐ToolStripMenuItem1"; // 南北对齐ToolStripMenuItem1.ShortcutKeyDisplayString = "Ctrl+1"; // 南北对齐ToolStripMenuItem1.Size = new Size(170, 22); // 南北对齐ToolStripMenuItem1.Text = "南北对齐"; // 南北对齐ToolStripMenuItem1.Click += 南北对齐ToolStripMenuItem_Click; // // // // 竖直对齐ToolStripMenuItem1 // // // 竖直对齐ToolStripMenuItem1.Name = "竖直对齐ToolStripMenuItem1"; // 竖直对齐ToolStripMenuItem1.ShortcutKeyDisplayString = "Ctrl+2"; // 竖直对齐ToolStripMenuItem1.Size = new Size(170, 22); // 竖直对齐ToolStripMenuItem1.Text = "竖直对齐"; // 竖直对齐ToolStripMenuItem1.Click += 竖直对齐ToolStripMenuItem_Click; // // // // 自动对齐ToolStripMenuItem1 // // // 自动对齐ToolStripMenuItem1.Name = "自动对齐ToolStripMenuItem1"; // 自动对齐ToolStripMenuItem1.ShortcutKeyDisplayString = "Ctrl+3"; // 自动对齐ToolStripMenuItem1.Size = new Size(170, 22); // 自动对齐ToolStripMenuItem1.Text = "自动对齐"; // 自动对齐ToolStripMenuItem1.Click += 自动对齐ToolStripMenuItem_Click; // // // // toolStripSeparator6 // // // toolStripSeparator6.Name = "toolStripSeparator6"; // toolStripSeparator6.Size = new Size(142, 6); // // // // 设置长度ToolStripMenuItem // // // 设置长度ToolStripMenuItem.Name = "设置长度ToolStripMenuItem"; // 设置长度ToolStripMenuItem.Size = new Size(145, 22); // 设置长度ToolStripMenuItem.Text = "设置长度"; // 设置长度ToolStripMenuItem.Click += 设置长度ToolStripMenuItem_Click; // // // // 设为关闭ToolStripMenuItem // // // 设为关闭ToolStripMenuItem.Name = "设为关闭ToolStripMenuItem"; // 设为关闭ToolStripMenuItem.Size = new Size(145, 22); // 设为关闭ToolStripMenuItem.Text = "设为关闭"; // 设为关闭ToolStripMenuItem.Click += 设为关闭ToolStripMenuItem_Click; // // // // 设为立管点ToolStripMenuItem // // // 设为立管点ToolStripMenuItem.Name = "设为立管点ToolStripMenuItem"; // 设为立管点ToolStripMenuItem.Size = new Size(145, 22); // 设为立管点ToolStripMenuItem.Text = "设为立管点"; // 设为立管点ToolStripMenuItem.Click += 设为立管点ToolStripMenuItem_Click; // // // // 设为隐藏ToolStripMenuItem // // // 设为隐藏ToolStripMenuItem.Name = "设为隐藏ToolStripMenuItem"; // 设为隐藏ToolStripMenuItem.Size = new Size(145, 22); // 设为隐藏ToolStripMenuItem.Text = "设为隐藏"; // 设为隐藏ToolStripMenuItem.Click += 设为隐藏ToolStripMenuItem_Click; // // // // 显示ToolStripMenuItem // // // 显示ToolStripMenuItem.Name = "显示ToolStripMenuItem"; // 显示ToolStripMenuItem.Size = new Size(145, 22); // 显示ToolStripMenuItem.Text = "全部显示"; // 显示ToolStripMenuItem.Click += 全部显示ToolStripMenuItem_Click; // // // // toolStripSeparator11 // // // toolStripSeparator11.Name = "toolStripSeparator11"; // toolStripSeparator11.Size = new Size(142, 6); // // // // 复制ToolStripMenuItem1 // // // 复制ToolStripMenuItem1.Name = "复制ToolStripMenuItem1"; // 复制ToolStripMenuItem1.ShortcutKeyDisplayString = "Ctrl+C"; // 复制ToolStripMenuItem1.Size = new Size(145, 22); // 复制ToolStripMenuItem1.Text = "复制"; // 复制ToolStripMenuItem1.Click += 复制ToolStripMenuItem_Click; // // // // 粘贴ToolStripMenuItem1 // // // 粘贴ToolStripMenuItem1.Name = "粘贴ToolStripMenuItem1"; // 粘贴ToolStripMenuItem1.ShortcutKeyDisplayString = "Ctrl+V"; // 粘贴ToolStripMenuItem1.Size = new Size(145, 22); // 粘贴ToolStripMenuItem1.Text = "粘贴"; // 粘贴ToolStripMenuItem1.Click += 粘贴ToolStripMenuItem1_Click; // // // // 转换为ToolStripMenuItem // // // 转换为ToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { 基本节点ToolStripMenuItem, 用户点ToolStripMenuItem, 水库ToolStripMenuItem, 水池ToolStripMenuItem }); // 转换为ToolStripMenuItem.Name = "转换为ToolStripMenuItem"; // 转换为ToolStripMenuItem.Size = new Size(145, 22); // 转换为ToolStripMenuItem.Text = "转换为"; // // // // 基本节点ToolStripMenuItem // // // 基本节点ToolStripMenuItem.Name = "基本节点ToolStripMenuItem"; // 基本节点ToolStripMenuItem.Size = new Size(124, 22); // 基本节点ToolStripMenuItem.Text = "基本节点"; // 基本节点ToolStripMenuItem.Click += 转换ToolStripMenuItem_Click; // // // // 用户点ToolStripMenuItem // // // 用户点ToolStripMenuItem.Name = "用户点ToolStripMenuItem"; // 用户点ToolStripMenuItem.Size = new Size(124, 22); // 用户点ToolStripMenuItem.Text = "水表"; // 用户点ToolStripMenuItem.Click += 转换ToolStripMenuItem_Click; // // // // 水库ToolStripMenuItem // // // 水库ToolStripMenuItem.Name = "水库ToolStripMenuItem"; // 水库ToolStripMenuItem.Size = new Size(124, 22); // 水库ToolStripMenuItem.Text = "水库"; // 水库ToolStripMenuItem.Click += 转换ToolStripMenuItem_Click; // // // // 水池ToolStripMenuItem // // // 水池ToolStripMenuItem.Name = "水池ToolStripMenuItem"; // 水池ToolStripMenuItem.Size = new Size(124, 22); // 水池ToolStripMenuItem.Text = "水池"; // 水池ToolStripMenuItem.Click += 转换ToolStripMenuItem_Click; // // // // 删除ToolStripMenuItem // // // 删除ToolStripMenuItem.Name = "删除ToolStripMenuItem"; // 删除ToolStripMenuItem.ShortcutKeyDisplayString = "Delete"; // 删除ToolStripMenuItem.Size = new Size(145, 22); // 删除ToolStripMenuItem.Text = "删除"; // 删除ToolStripMenuItem.Click += 删除ToolStripMenuItem_Click; // // // // toolStripSeparator9 // // // toolStripSeparator9.Name = "toolStripSeparator9"; // toolStripSeparator9.Size = new Size(142, 6); // // // // 全选ToolStripMenuItem // // // 全选ToolStripMenuItem.Name = "全选ToolStripMenuItem"; // 全选ToolStripMenuItem.Size = new Size(145, 22); // 全选ToolStripMenuItem.Text = "全选"; // 全选ToolStripMenuItem.Click += 全选ToolStripMenuItem_Click; // // // // 反选ToolStripMenuItem // // // 反选ToolStripMenuItem.Name = "反选ToolStripMenuItem"; // 反选ToolStripMenuItem.Size = new Size(145, 22); // 反选ToolStripMenuItem.Text = "反选"; // 反选ToolStripMenuItem.Click += 反选ToolStripMenuItem_Click; // // // // propertyForm // // // propertyForm.Dock = DockStyle.Right; // propertyForm.Location = new Point(815, 24); // propertyForm.Margin = new Padding(4, 4, 4, 4); // propertyForm.Name = "propertyForm"; // propertyForm.Size = new Size(236, 554); // propertyForm.TabIndex = 1; // // // // timer_draw // // // timer_draw.Enabled = true; // timer_draw.Interval = 33; // timer_draw.Tick += timer_draw_Tick; // // // // map // // // map._newTemplate = null; // map.Dock = DockStyle.Fill; // map.Location = new Point(0, 24); // map.mapOption = null; // map.Name = "map"; // map.Size = new Size(1051, 554); // map.TabIndex = 8; // // // // CubeView // // // CubeView._newTemplate = null; // CubeView.Anchor = AnchorStyles.Top | AnchorStyles.Right; // CubeView.BackColor = SystemColors.GradientInactiveCaption; // CubeView.Location = new Point(677, 26); // CubeView.mapOption = null; // CubeView.Name = "CubeView"; // CubeView.Size = new Size(120, 120); // CubeView.TabIndex = 0; // // // // MapViewer // // // Controls.Add(CubeView); // Controls.Add(propertyForm); // Controls.Add(map); // Controls.Add(panel1); // Controls.Add(statusStrip1); // Name = "MapViewer"; // Size = new Size(1051, 600); // Load += MapViewer_Load; // KeyDown += MapViewer_KeyDown; // KeyPress += MapViewer_KeyPress; // PreviewKeyDown += MapViewer_PreKeyPress; // statusStrip1.ResumeLayout(false); // statusStrip1.PerformLayout(); // panel1.ResumeLayout(false); // panel1.PerformLayout(); // toolStrip1.ResumeLayout(false); // toolStrip1.PerformLayout(); // 右键_Menu.ResumeLayout(false); // ResumeLayout(false); // PerformLayout(); // } // private Bitmap buffer; // private ToolStripMenuItem 俯视图ToolStripMenuItem; // private ToolStripMenuItem 正视图ToolStripMenuItem; // private ToolStripMenuItem 重置视角ToolStripMenuItem; // private ToolStripMenuItem 设为隐藏ToolStripMenuItem; // private ToolStripMenuItem 显示ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator11; // private ToolStripMenuItem 复制ToolStripMenuItem; // private ToolStripMenuItem 粘贴ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator12; // private ToolStripMenuItem 设置长度ToolStripMenuItem; // private ToolStripMenuItem 标高推测ToolStripMenuItem; // private ToolStripMenuItem 标高导出ToolStripMenuItem; // private ToolStripMenuItem 旧版打开ToolStripMenuItem; // private ToolStripSplitButton toolStripButton_save; // private ToolStripMenuItem 另存为ToolStripMenuItem; // private ToolStripMenuItem 以当前视角另存ToolStripMenuItem; // private ToolStripMenuItem 连通性检查ToolStripMenuItem1; // private ToolStripMenuItem 复制ToolStripMenuItem1; // private ToolStripMenuItem 粘贴ToolStripMenuItem1; // private ToolStripMenuItem 增量保存ToolStripMenuItem; // private ToolStripMenuItem 设为关闭ToolStripMenuItem; // private ToolStripDropDownButton toolStripDropDownButton1; // private ToolStripMenuItem 显示节点ToolStripMenuItem; // private ToolStripMenuItem 隐藏节点ToolStripMenuItem; // private ToolStripMenuItem 节点大小ToolStripMenuItem; // private ToolStripMenuItem 大ToolStripMenuItem; // private ToolStripMenuItem 中ToolStripMenuItem; // private ToolStripMenuItem 小ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator10; // private ToolStripMenuItem 显示阀门ToolStripMenuItem; // private ToolStripMenuItem 隐藏阀门ToolStripMenuItem; // private ToolStripMenuItem 管线粗细ToolStripMenuItem; // private ToolStripMenuItem 大ToolStripMenuItem1; // private ToolStripMenuItem 中ToolStripMenuItem1; // private ToolStripMenuItem 小ToolStripMenuItem1; // private ToolStripSeparator toolStripSeparator13; // private ToolStripMenuItem 缩放级别ToolStripMenuItem; // private ToolStripMenuItem 放大ToolStripMenuItem2; // private ToolStripMenuItem 正常ToolStripMenuItem; // private ToolStripMenuItem 缩小ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator5; // private ToolStripMenuItem 隐藏内容ToolStripMenuItem; // private ToolStripMenuItem 显示所有隐藏内容ToolStripMenuItem; // private ToolStripMenuItem 隐藏ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator14; // private ToolStripMenuItem ToolStripMenuItem_Floor; // private ToolStripMenuItem 保存楼层视角ToolStripMenuItem; // private ToolStripMenuItem 显示全部楼层ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator15; // private ToolStripMenuItem 对齐ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator16; // private ToolStripMenuItem 南北对齐ToolStripMenuItem; // private ToolStripMenuItem 东西对齐ToolStripMenuItem; // private ToolStripMenuItem 竖直对齐ToolStripMenuItem; // private ToolStripMenuItem 排列ToolStripMenuItem; // private ToolStripMenuItem 对齐ToolStripMenuItem1; // private ToolStripMenuItem 东西对齐ToolStripMenuItem1; // private ToolStripMenuItem 南北对齐ToolStripMenuItem1; // private ToolStripMenuItem 自动对齐ToolStripMenuItem; // private ToolStripMenuItem 竖直对齐ToolStripMenuItem1; // private ToolStripMenuItem 自动对齐ToolStripMenuItem1; // private ToolStripMenuItem 删除ToolStripMenuItem1; // private ToolStripSeparator toolStripSeparator17; // private ToolStripMenuItem 添加底图ToolStripMenuItem; // private ToolStripMenuItem 设置底图ToolStripMenuItem; // private ToolStripMenuItem 显示隐藏底图ToolStripMenuItem; // private ToolStripMenuItem 清除底图ToolStripMenuItem; // private ToolStripMenuItem 设为立管点ToolStripMenuItem; // private ToolStripMenuItem 下游连通性ToolStripMenuItem; // private ToolStripMenuItem 上游连通性ToolStripMenuItem; // private StatusStrip statusStrip1; // private ToolStripStatusLabel label_center; // private ToolStripStatusLabel label_zoom; // private ToolStripStatusLabel label_mouse; // private Panel panel1; // private ToolStrip toolStrip1; // private ToolStripSplitButton toolStripSplitButton1; // private ToolStripSplitButton toolStripSplitButton2; // private ToolStripMenuItem 新建ToolStripMenuItem; // private ToolStripMenuItem toolStripMenuItem2; // private ToolStripMenuItem toolStripMenuItem3; // private ToolStripMenuItem toolStripMenuItem4; // private ToolStripMenuItem toolStripMenuItem5; // private ToolStripMenuItem toolStripMenuItem6; // private ToolStripMenuItem toolStripMenuItem7; // private ToolStripMenuItem toolStripMenuItem8; // private ToolStripSeparator toolStripSeparator1; // private ToolStripSeparator toolStripSeparator2; // private ToolStripButton toolStripButton_新建节点; // private ToolStripButton toolStripButton_新建管线; // private ToolStripButton toolStripButton_添加水库; // private ToolStripButton toolStripButton_添加水池; // private ToolStripButton toolStripButton_添加水泵; // private ToolStripButton toolStripButton_添加阀门; // private ToolStripButton toolStripButton_添加水表; // private ToolStripMenuItem 重置ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator3; // private ToolStripSeparator toolStripSeparator4; // private ToolStripButton toolStripButton_重复器; // private ToolStripMenuItem 打开文件位置ToolStripMenuItem; // private ToolStripButton toolStripButton_普通; // private ContextMenuStrip 右键_Menu; // private ToolStripMenuItem 转换为ToolStripMenuItem; // private ToolStripMenuItem 基本节点ToolStripMenuItem; // private ToolStripMenuItem 用户点ToolStripMenuItem; // private ToolStripMenuItem 水库ToolStripMenuItem; // private ToolStripMenuItem 水池ToolStripMenuItem; // private ToolStripMenuItem 删除ToolStripMenuItem; // private ToolStripMenuItem ePA中打开ToolStripMenuItem; // private ToolStripMenuItem 视角ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator6; // private ToolStripSplitButton toolStripComboBox_浏览模式; // private ToolStripMenuItem 浏览模式ToolStripMenuItem; // private ToolStripMenuItem 编辑模式ToolStripMenuItem; // private ToolStripDropDownButton toolStripDropDownButton_工具; // private ToolStripMenuItem 水平旋转ToolStripMenuItem; // private ToolStripMenuItem 轴旋转ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator7; // private ToolStripMenuItem 缩放ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator8; // private ToolStripButton buttonUndo; // private ToolStripButton buttonRedo; // private ToolStripStatusLabel toolStripStatusLabel_split1; // private ToolStripStatusLabel toolStripStatusLabel_split2; // private ToolStripStatusLabel label_file; // private ToolStripMenuItem 轴镜像ToolStripMenuItem; // private ToolStripTextBox toolStripTextBox_水平旋转角度; // private ToolStripTextBox toolStripTextBox_缩放比例; // private ToolStripMenuItem toolStripMenuItem_放大2倍; // private ToolStripMenuItem toolStripMenuItem_缩小2倍; // private ToolStripStatusLabel toolStripStatusLabel_rotation; // private ToolStripButton toolStripButton_刷新; // private bool is45view = true; // private ToolStripMenuItem 关阀分析ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator9; // private ToolStripMenuItem 关阀分析不考虑水源ToolStripMenuItem; // #endregion // #endregion // private ToolStripMenuItem 显示水流ToolStripMenuItem; // private ToolStripMenuItem 全选ToolStripMenuItem; // private ToolStripMenuItem 反选ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator18; // private ToolStripMenuItem 显示状态ToolStripMenuItem; // private ToolStripMenuItem 隐藏状态ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator19; // private ToolStripMenuItem 显示流向ToolStripMenuItem; // private ToolStripMenuItem 隐藏流向ToolStripMenuItem; // private ToolStripButton toolStripButton_新建立管; // private ToolStripMenuItem 方向修复ToolStripMenuItem; // private ToolStripMenuItem 刷新楼层ToolStripMenuItem; // private ToolStripButton toolStripButton_ClearMinor; // public ToolStripComboBox cb_Link_Colour; // public ToolStripComboBox cb_Node_Colour; // private ToolStripSeparator toolStripSeparator20; // private ToolStripMenuItem 颜色分级管理ToolStripMenuItem; // private ToolStripButton tb_颜色分级设置; // private ToolStripSeparator toolStripSeparator21; // private System.Windows.Forms.Timer timer_draw; // private ToolStripStatusLabel label_ZZ; // private ToolStripSeparator toolStripSeparator22; // private ToolStripMenuItem 楼层管理ToolStripMenuItem; // private ToolStripMenuItem 默认视角ToolStripMenuItem; // private ToolStripMenuItem 水量分配ToolStripMenuItem; // private ToolStripSeparator toolStripSeparator23; // private DMap map; // private ToolStripMenuItem 计算局部损失ToolStripMenuItem; // private ToolStripButton btn_水量初分配; // private DMap CubeView; // private PropertyForm propertyForm; //} partial class MapViewer { void DrawBackGroud(Graphics bufferG, Template template) { if (template == null) return; var _Nodes = template.network.Nodes.ViewNodes; var _Links = template.network.Links.ViewLinks; var Cpoints = getCurclePoints(64).ToList(); var r = 1.73f / zoom; var rt = r; r = r * Link_multiply; List diametersZoom = new List() { new PointF(0, 0.08f), new PointF(150, 0.03f), new PointF(300, 0.001f), new PointF(800, 0.0001f) }; Pen penN = new Pen(Color.FromArgb(0, 0, 255), 1 * r); //背景图绘制 if (this.mapOption.isShowPic && template != null && File.Exists(template.BackGroundImg_FullPath)) { //var gs = bufferG.Save(); // 应用矩阵变换以抵消之前的翻转效果 //bufferG.ScaleTransform(1 / Zoom.X, 1 / Zoom.Y); List p = new List(); if (!this.mapOption.isAutoBackgroundImage) { var Cps = new List { template.BackGroundPoint1, new PointF(template.BackGroundPoint2.X,template.BackGroundPoint1.Y), new PointF(template.BackGroundPoint1.X,template.BackGroundPoint2.Y), //template.BackGroundPoint2, }; Cps.ForEach(cp => p.Add(WorldPointToMapPoint(cp, template.BackGroundElev, template.OffSet))); } else { // 恢复之前保存的绘图状态 //var Cps = new List //{ //template.BackGroundPoint1, //new PointF(template.BackGroundPoint2.X,template.BackGroundPoint1.Y), //new PointF(template.BackGroundPoint1.X,template.BackGroundPoint2.Y), ////template.BackGroundPoint2, //}; var p1 = new PointF(template.BackGroundImgX, template.BackGroundImgY); var p2 = new PointF(template.BackGroundImgX + template.BackGroundImgWidth, template.BackGroundImgY + template.BackGroundImgHeight); var f = template.BackGroundImgRotaAngle / 180 * Math.PI; var djx = Math.Sqrt((Math.Pow(template.BackGroundImgWidth, 2) + Math.Pow(template.BackGroundImgHeight, 2))); var p3 = new PointF(p1.X + (float)(Math.Cos(f) * template.BackGroundImgWidth), p1.Y + (float)(Math.Sin(f) * template.BackGroundImgWidth)); var p4 = new PointF(p1.X - (float)(Math.Sin(f) * template.BackGroundImgHeight), p1.Y + (float)(Math.Cos(f) * template.BackGroundImgHeight)); p3.Y = p4.Y; //p4.Y = -p4.Y; var Cps = new List { //template.BackGroundPoint1, //new PointF(template.BackGroundImgX,template.BackGroundImgY), p4, p3,p1 //template.BackGroundPoint2, }; template.BackGroundPoint1 = p4; template.BackGroundPoint2 = new PointF(p3.X, p1.Y); //List p = new List(); Cps.ForEach(cp => p.Add(WorldPointToMapPoint(cp, template.BackGroundElev, template.OffSet))); } //bufferG.DrawImage(System.Drawing.Image.FromFile(@"C:\Users\cloud\Pictures\GenshinImpactCloudGame\QQ截图20230919105637.png"), p[0]); try { var img = System.Drawing.Image.FromFile(template.BackGroundImg_FullPath); if (img != null) { bufferG.FillPolygon(penN.Brush, p.ToArray()); bufferG.DrawImage(img, p.ToArray()); } } catch { } //bufferG.Restore(gs); } } void Draw(Graphics bufferG, Template template) { if (template == null) return; var _Nodes = template.network.Nodes.ViewNodes; var _Links = template.network.Links.ViewLinks; var _Areas = template.network.Areas; var Cpoints = getCurclePoints(64).ToList(); var r = 1.73f / zoom; var rt = r; float minElve = float.MinValue; float maxElve = float.MaxValue; //if (this.mapOption!=null && this.mapOption.ShowFloor!=int.MinValue ) //{ //var fl = template.Floors.Find(f => f.FloorIndex == this.mapOption.ShowFloor); //var fl_1 = template.Floors.Find(f => f.FloorIndex == this.mapOption.ShowFloor+1); //if (fl!=null) //{ //minElve = fl.Elev; //maxElve = fl_1!=null ? fl_1.Elev : float.MaxValue; //} //} r = r * Link_multiply; List diametersZoom = new List() { new PointF(0, 0.08f), new PointF(150, 0.03f), new PointF(300, 0.001f), new PointF(800, 0.0001f) }; Pen penN = new Pen(Color.FromArgb(0, 0, 255), 1 * r); Pen penChoosed = new Pen(Color.Purple, 5 * r); Pen pen_valveChoosed = new Pen(Color.Red, 5 * r); Pen penClosed = new Pen(Color.OrangeRed, 2 * r); Pen penHovered = new Pen(Color.DeepSkyBlue, 5 * r); //绘制面 using (Pen pen0 = new Pen(Color.FromArgb(0, 0, 255), 2 * r)) { foreach (var area in _Areas) { if (!area.Visible) continue; if (!IsFaceVisibleToCamera(area, GetCameraPosition())) continue; if (area.Elev < minElve || area.Elev >= maxElve) continue; var p = new List(); foreach (var node in area.InnerNodes) { p.Add(CubeWorldPointToMapPoint(node, template.OffSet)); } if (p.Count < 3) continue; pen0.Color = penClosed.Color = area.color; Pen pen = pen0; if (area.Hovered) pen = penHovered; bufferG.FillPolygon(pen.Brush, p.ToArray()); bufferG.DrawPolygon(pen, p.ToArray()); //显示area的名称 var c = new PointF(p.Average(p0 => p0.X), p.Average(p0 => p0.Y)); var brush = new SolidBrush(Color.White); var gs = bufferG.Save(); // 应用矩阵变换以抵消之前的翻转效果 bufferG.ScaleTransform(1 / Zoom.X, 1 / Zoom.Y); Font font = new Font(FontFamily.GenericSansSerif, 10 * 10 * zoom); SizeF textSize = bufferG.MeasureString(area.Name, font); var center = new PointF(c.X * Zoom.X, c.Y * Zoom.Y); float textLeft = center.X - textSize.Width / 2; float textTop = center.Y - textSize.Height / 2; PointF pd = new PointF(textLeft, textTop); bufferG.DrawString(area.Name, font, brush, pd); // 恢复之前保存的绘图状态 bufferG.Restore(gs); } } // 绘制线 HashSet dict_flow_direction = new HashSet(); using (Pen pen0 = new Pen(Color.FromArgb(0, 0, 255), 2 * r)) { foreach (var link in _Links) { if (!link.Visible) continue; if (link.Elev < minElve || link.Elev >= maxElve) continue; //if (_isMovingObject && (link.StartNode == _OperaNode || link.EndNode == _OperaNode)) continue; var p1 = WorldPointToMapPoint(link.StartNode, template.OffSet); var p2 = WorldPointToMapPoint(link.EndNode, template.OffSet); if (!isVisible(p1) && !isVisible(p2)) continue; if (LinkColour != null) { pen0.Color = penClosed.Color = GraphHelper.getLinkColor(LinkColour, link); } Pen pen = pen0; #if DEBUG #else if (_Template != null && _Template.mapOption._ShowStatus && link.Status == Hydro.Core.StatusType.CLOSED) pen = penClosed; #endif if (link.Hovered) pen = penHovered; float zoomAtMin = 0; for (int i = 0; i < diametersZoom.Count; i++) { PointF point = diametersZoom[i]; if (link.Diameter >= point.X) continue; zoomAtMin = diametersZoom[i - 1].Y; break; } if (zoomAtMin >= zoom) continue; if (link is ValveViewModel) { if (link.Selected || _ShowValve) { var c = new PointF((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2); bufferG.DrawLines(link.Selected ? penChoosed : pen, new PointF[] { p1, p2 }); var valveShapeHeight = link.Selected ? 10 : 5; PointF[] points = new PointF[] { GraphHelper.getRotatePoint(c.X - valveShapeHeight * r, c.Y + valveShapeHeight * r,c,p1,p2), GraphHelper.getRotatePoint(c.X - valveShapeHeight * r, c.Y - valveShapeHeight * r,c,p1,p2), GraphHelper.getRotatePoint(c.X + valveShapeHeight * r, c.Y + valveShapeHeight * r,c,p1,p2), GraphHelper.getRotatePoint(c.X + valveShapeHeight * r, c.Y - valveShapeHeight * r,c,p1,p2), GraphHelper.getRotatePoint(c.X - valveShapeHeight * r, c.Y + valveShapeHeight * r,c,p1,p2), }; bufferG.FillPolygon(link.Selected ? pen_valveChoosed.Brush : pen.Brush, points); } } else if (link is PumpViewModel) { if (link.Selected || _ShowValve) { var c = new PointF((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2); //bufferG.DrawLine(link.Selected ? pen_valveChoosed : pen, p1, p2); bufferG.DrawLines(link.Selected ? penChoosed : pen, new PointF[] { p1, p2 }); // 绘制圆形部分(水泵的泵体) float radius = 5 * r; float diameter = radius * 2; #region 圆形拆分 //var p = new PointF[] //{ //GraphHelper.getRotatePoint(c.X - radius - radius, c.Y - radius, c, p1, p2), //GraphHelper.getRotatePoint(c.X + radius - radius, c.Y - radius, c, p1, p2), //GraphHelper.getRotatePoint(c.X + radius - radius, c.Y + radius, c, p1, p2), //GraphHelper.getRotatePoint(c.X - radius - radius, c.Y + radius, c, p1, p2), //GraphHelper.getRotatePoint(c.X - radius - radius, c.Y - radius, c, p1, p2), //}; List p = new List(); Cpoints.ForEach(cp => p.Add(GraphHelper.getRotatePoint(c.X + cp.X * radius - radius, c.Y + cp.Y * radius, c, p1, p2))); #endregion //RectangleF circleRect = new RectangleF(p[0].X, p[0].Y,p[1].X-p[0].X>0? diameter:-diameter,p[1].Y-p[0].Y>0? diameter:-diameter); //bufferG.FillEllipse(link.Selected ? pen_valveChoosed.Brush : pen.Brush, circleRect); bufferG.FillPolygon(link.Selected ? pen_valveChoosed.Brush : pen.Brush, p.ToArray()); //// 绘制矩形部分(水泵的出口) //float rectangleWidth = 6*r; //float rectangleHeight = 2*r; //PointF rectTopLeft = new PointF(c.X - rectangleWidth / 2, c.Y + radius); //SizeF rectSize = new SizeF(rectangleWidth, rectangleHeight); //RectangleF rectangleRect = new RectangleF(rectTopLeft, rectSize); //bufferG.DrawRectangles(link.Selected ? pen_valveChoosed : pen,new RectangleF[] { rectangleRect }); // 绘制连接线 var valveShapeHeight = link.Selected ? radius * 2 : radius; PointF[] points = new PointF[] { GraphHelper.getRotatePoint(c.X - valveShapeHeight , c.Y + valveShapeHeight ,c,p1,p2), GraphHelper.getRotatePoint(c.X - valveShapeHeight , c.Y ,c,p1,p2), GraphHelper.getRotatePoint(c.X + valveShapeHeight , c.Y ,c,p1,p2), GraphHelper.getRotatePoint(c.X + valveShapeHeight , c.Y + valveShapeHeight ,c,p1,p2), GraphHelper.getRotatePoint(c.X - valveShapeHeight , c.Y + valveShapeHeight ,c,p1,p2), }; bufferG.FillPolygon(link.Selected ? pen_valveChoosed.Brush : pen.Brush, points); } } else if (link is RepeaterViewModel re) { if (re.Status == RepeaterViewModel.RepeatStatus.收起 || _IsEditMode) { bufferG.DrawLines(link.Selected ? penChoosed : pen, new PointF[] { p1, p2 }); var listNode = GraphHelper.Get等分Nodes(p1, p2, Math.Max(re.RepeatTimes, 1)); for (int i = 0; i < listNode.Count; i++) { //foreach (var c in listNode) //{ var c = listNode[i]; RectangleF[] rects = new RectangleF[] { new RectangleF(c.X-10*r,c.Y-8*r,20*r,16*r), }; bufferG.FillRectangles(new SolidBrush(Color.White), rects); //bufferG.FillRectangles(link.Selected ? penChoosed.Brush : pen.Brush, new RectangleF[] //{ //new RectangleF(c.X-5*r,c.Y-5*r,3*r,3*r), //new RectangleF(c.X-5*r,c.Y+2*r,3*r,3*r), //new RectangleF(c.X+2*r,c.Y+2*r,3*r,3*r), //new RectangleF(c.X+2*r,c.Y-5*r,3*r,3*r), //}); // 保存当前绘图状态 var gs = bufferG.Save(); // 应用矩阵变换以抵消之前的翻转效果 bufferG.ScaleTransform(1 / Zoom.X, 1 / Zoom.Y); int index = re.GetIndex(i); string indexString = index == 0 ? "" : index.ToString(); Font font = new Font(FontFamily.GenericSansSerif, 10); string text = $"{indexString}{re.NetworkShowName}"; SizeF textSize = bufferG.MeasureString(text, font); var center = new PointF(c.X * Zoom.X, c.Y * Zoom.Y); float textLeft = center.X - textSize.Width / 2; float textTop = center.Y - textSize.Height / 2; PointF p = new PointF(textLeft, textTop); bufferG.DrawString(text, font, link.Selected ? penChoosed.Brush : pen.Brush, p); // 恢复之前保存的绘图状态 bufferG.Restore(gs); if (textSize.Width / Zoom.X > rects[0].Width) { rects[0] = new RectangleF(c.X - textSize.Width / 2 / Zoom.X - 1 * r, c.Y - 8 * r, textSize.Width / Zoom.X + 2 * r, 16 * r); } try { bufferG.DrawRectangles(penN, rects); } catch { } } //var c = new PointF((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2); } //else //{ //DrawRepeater(bufferG,re); //} } else { if (link.StartNode == null || link.EndNode == null) continue; try { bufferG.DrawLines(link.Selected ? penChoosed : pen, new PointF[] { p1, p2 }); } catch (Exception) { } if (_Template.mapOption._ShowFlowDirection) { var c = new PointF((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2); var ps = MapToScreen(c); //将ps转换为ulong,精度为20,并加入到dict_flow_direction中 var ps_20 = GraphHelper.GetUlongByPoint(ps, 5); if (!dict_flow_direction.Contains(ps_20)) { dict_flow_direction.Add(ps_20); bufferG.DrawLines(link.Selected ? penChoosed : pen, new PointF[] { p1, p2 }); // 绘制圆形部分(水泵的泵体) float radius = 5 * r; float diameter = radius * 2; #region 圆形拆分 float activeD = 1; if (link.EN_FLOW < 0) activeD = -1; List p = new List(); Cpoints.ForEach(cp => p.Add(GraphHelper.getRotatePoint(c.X - activeD * cp.X * radius + activeD * radius, c.Y + cp.Y * radius, c, p1, p2))); #endregion bufferG.FillPolygon(link.Selected ? pen_valveChoosed.Brush : pen.Brush, p.ToArray()); var valveShapeHeight = link.Selected ? radius * 2 : radius; PointF[] points = new PointF[] { GraphHelper.getRotatePoint(c.X -activeD* valveShapeHeight , c.Y + valveShapeHeight ,c,p1,p2), GraphHelper.getRotatePoint(c.X, c.Y ,c,p1,p2), GraphHelper.getRotatePoint(c.X - activeD*valveShapeHeight , c.Y - valveShapeHeight,c,p1,p2), GraphHelper.getRotatePoint(c.X + activeD*valveShapeHeight , c.Y - valveShapeHeight,c,p1,p2), GraphHelper.getRotatePoint(c.X + activeD*valveShapeHeight , c.Y + valveShapeHeight ,c,p1,p2), GraphHelper.getRotatePoint(c.X - activeD*valveShapeHeight , c.Y + valveShapeHeight ,c,p1,p2), }; bufferG.FillPolygon(link.Selected ? pen_valveChoosed.Brush : pen.Brush, points); } } } } } r = rt; HashSet dict_point = new HashSet(); //绘制点 penChoosed = new Pen(Color.Green, 1f * r); Brush brushChoosed = penChoosed.Brush; SolidBrush whiteBrush = new SolidBrush(Color.White); using (Pen pen0 = new Pen(Color.FromArgb(255, 0, 0), 1 * r)) { foreach (NodeViewModel node in _Nodes) { if (!node.Visible) continue; if (node.Elev < minElve || node.Elev >= maxElve) continue; Pen pen = pen0; Brush brush = pen.Brush; float pr = (float)(r * 0.5); pr = pr * junction_multiply; PointF p = WorldPointToMapPoint(node, template.OffSet); if (!isVisible(p)) continue; var ps_20 = GraphHelper.GetUlongByPoint(p, 0.1f); if (dict_point.Contains(ps_20)) continue; dict_point.Add(ps_20); //var x = junction.Position.X * zoom + PanningOffset.X - radius / 2.0f; //var y = junction.Position.Y * zoom + PanningOffset.Y - radius / 2.0f; if (NodeColour != null) { pen.Color = penChoosed.Color = GraphHelper.getNodeColor(NodeColour, node); brush = pen.Brush; brushChoosed = penChoosed.Brush; } if (node.Hovered) { pen = penHovered; brush = pen.Brush; pr = pr * 2; } var rectangle = new RectangleF((float)p.X - 5 * pr, (float)p.Y - 5 * pr, 10 * pr, 10 * pr); float zoomAtMin = 0; for (int i = 0; i < diametersZoom.Count; i++) { PointF point = diametersZoom[i]; if (node.MaxDiameter >= point.X) continue; zoomAtMin = diametersZoom[i - 1].Y; break; } if (zoomAtMin >= zoom) continue; //if(node.ID == _StartPoint) //{ //var whiteRect = new RectangleF(rectangle.X - 4 * pr, rectangle.Y - 4 * pr, rectangle.Width + 8 * pr, rectangle.Height + 8 * pr); //bufferG.FillEllipse(whiteBrush, whiteRect); //whiteRect = new RectangleF(rectangle.X + 2 * pr, rectangle.Y + 2 * pr, rectangle.Width - 4 * pr, rectangle.Height - 4 * pr); //bufferG.DrawEllipse(node.Selected ? penChoosed : pen, whiteRect); //whiteRect = new RectangleF(rectangle.X - 4 * pr, rectangle.Y - 4 * pr, rectangle.Width + 8 * pr, rectangle.Height + 8 * pr); //bufferG.DrawEllipse(node.Selected ? penChoosed : pen, whiteRect); //} //else if (node == _OperaNode) { //bufferG.DrawEllipse(junction.Choosed ? penChoosed : pen, rectangle); var whiteRect = new RectangleF(rectangle.X - 4 * pr, rectangle.Y - 4 * pr, rectangle.Width + 8 * pr, rectangle.Height + 8 * pr); bufferG.FillEllipse(whiteBrush, whiteRect); whiteRect = new RectangleF(rectangle.X + 2 * pr, rectangle.Y + 2 * pr, rectangle.Width - 4 * pr, rectangle.Height - 4 * pr); bufferG.DrawEllipse(node.Selected ? penChoosed : pen, whiteRect); whiteRect = new RectangleF(rectangle.X - 4 * pr, rectangle.Y - 4 * pr, rectangle.Width + 8 * pr, rectangle.Height + 8 * pr); bufferG.DrawEllipse(node.Selected ? penChoosed : pen, whiteRect); //bufferG.DrawEllipse(junction.Choosed ? penChoosed : pen, rectangle); } else if (node.ID == _EndPoint) { var whiteRect = new RectangleF(rectangle.X - 4 * pr, rectangle.Y - 4 * pr, rectangle.Width + 8 * pr, rectangle.Height + 8 * pr); bufferG.FillEllipse(whiteBrush, whiteRect); whiteRect = new RectangleF(rectangle.X - 4 * pr, rectangle.Y - 4 * pr, rectangle.Width + 8 * pr, rectangle.Height + 8 * pr); bufferG.DrawEllipse(node.Selected ? penChoosed : pen, whiteRect); //whiteRect = new RectangleF(rectangle.X + 2 * pr, rectangle.Y + 2 * pr, rectangle.Width - 4 * pr, rectangle.Height - 4 * pr); //bufferG.DrawEllipse(junction.Choosed ? penChoosed : pen, whiteRect); var p1 = new PointF(rectangle.X + 2 * pr, rectangle.Y + 2 * pr); var p2 = new PointF(p1.X + 6 * pr, p1.Y + 6 * pr); bufferG.DrawLine(node.Selected ? penChoosed : pen, p1, p2); p1 = new PointF(rectangle.X + 2 * pr, rectangle.Y + 8 * pr); p2 = new PointF(p1.X + 6 * pr, p1.Y - 6 * pr); bufferG.DrawLine(node.Selected ? penChoosed : pen, p1, p2); //bufferG.FillEllipse(junction.Choosed ? brushChoosed : brush, rectangle); //var whiteRect = new RectangleF(rectangle.X + 1 * pr, rectangle.Y + 1 * pr, rectangle.Width - 2 * pr, rectangle.Height - 2 * pr); //bufferG.FillEllipse(whiteBrush, whiteRect); //whiteRect = new RectangleF(rectangle.X - 2 * pr, rectangle.Y - 2 * pr, rectangle.Width + 4 * pr, rectangle.Height + 4 * pr); //bufferG.DrawEllipse(junction.Choosed ? penChoosed : pen, whiteRect); } else if (node is TankViewModel) { pr *= 2; rectangle = new RectangleF((float)p.X - 5 * pr, (float)p.Y - 5 * pr, 10 * pr, 10 * pr); RectangleF r0 = new RectangleF(rectangle.X, rectangle.Y + 5 * pr, 10 * pr, 5 * pr); RectangleF r1 = new RectangleF(rectangle.X + 2 * pr, rectangle.Y, 6 * pr, 5 * pr); bufferG.FillRectangle(node.Selected ? brushChoosed : brush, r0); bufferG.FillRectangle(node.Selected ? brushChoosed : brush, r1); } else if (node is ReservoirViewModel) { pr *= 2; rectangle = new RectangleF((float)p.X - 5 * pr, (float)p.Y - 5 * pr, 10 * pr, 10 * pr); RectangleF r0 = new RectangleF(rectangle.X, rectangle.Y + 2 * pr, rectangle.Width, 6 * pr); RectangleF r1 = new RectangleF(rectangle.X, rectangle.Y + 8 * pr, 1 * pr, 2 * pr); RectangleF r2 = new RectangleF(rectangle.X + 9 * pr, rectangle.Y + 8 * pr, 1 * pr, 2 * pr); bufferG.FillRectangle(node.Selected ? brushChoosed : brush, r0); bufferG.FillRectangle(node.Selected ? brushChoosed : brush, r1); bufferG.FillRectangle(node.Selected ? brushChoosed : brush, r2); } else if (node is MeterViewModel) { //bufferG.DrawEllipse(junction.Choosed ? penChoosed : pen, rectangle); bufferG.FillEllipse(node.Selected ? brushChoosed : brush, rectangle); var whiteRect = new RectangleF(rectangle.X + 1 * pr, rectangle.Y + 1 * pr, rectangle.Width - 2 * pr, rectangle.Height - 2 * pr); bufferG.FillEllipse(whiteBrush, whiteRect); var p1 = new PointF(rectangle.X + 5 * pr, rectangle.Y); var p2 = new PointF(rectangle.X + 5 * pr, rectangle.Y + 10 * pr); bufferG.DrawLine(node.Selected ? penChoosed : pen, p1, p2); } else { rectangle = new RectangleF((float)p.X - 3 * pr, (float)p.Y - 3 * pr, 6 * pr, 6 * pr); if (node.Selected || _ShowJunction) bufferG.FillEllipse(node.Selected ? brushChoosed : brush, rectangle); } } } using (Pen pen = new Pen(Color.FromArgb(255, 0, 0), 1 * r)) { Brush brush = pen.Brush; //获取_Nodes中自由水压最小的节点 var node = _Nodes.Where(n => n is JunctionViewModel || n is MeterViewModel && n.EN_PRESSURE != float.NaN).OrderBy(n => n.EN_PRESSURE).FirstOrDefault(); //判断node.EN_PRESSURE不是float.NaN if (node != null && !float.IsNaN(node.EN_PRESSURE)) { //if (node.Elev < minElve || node.Elev >= maxElve) continue; float pr = (float)(r * 0.5); pr = pr * junction_multiply; PointF p = WorldPointToMapPoint(node, template.OffSet); var ps_20 = GraphHelper.GetUlongByPoint(p, 0.1f); dict_point.Add(ps_20); //var x = junction.Position.X * zoom + PanningOffset.X - radius / 2.0f; //var y = junction.Position.Y * zoom + PanningOffset.Y - radius / 2.0f; if (NodeColour != null) { pen.Color = GraphHelper.getNodeColor(NodeColour, node); brush = pen.Brush; brushChoosed = penChoosed.Brush; } var rectangle = new RectangleF((float)p.X - 5 * pr, (float)p.Y - 5 * pr, 10 * pr, 10 * pr); float zoomAtMin = 0; for (int i = 0; i < diametersZoom.Count; i++) { PointF point = diametersZoom[i]; if (node.MaxDiameter >= point.X) continue; zoomAtMin = diametersZoom[i - 1].Y; break; } //var whiteRect = new RectangleF(rectangle.X - 4 * pr, rectangle.Y - 4 * pr, rectangle.Width + 8 * pr, rectangle.Height + 8 * pr); //bufferG.FillEllipse(whiteBrush, whiteRect); //whiteRect = new RectangleF(rectangle.X + 2 * pr, rectangle.Y + 2 * pr, rectangle.Width - 4 * pr, rectangle.Height - 4 * pr); //bufferG.DrawEllipse(node.Selected ? penChoosed : pen, whiteRect); //whiteRect = new RectangleF(rectangle.X - 4 * pr, rectangle.Y - 4 * pr, rectangle.Width + 8 * pr, rectangle.Height + 8 * pr); //bufferG.DrawEllipse(node.Selected ? penChoosed : pen, whiteRect); var p1 = new PointF((float)p.X - 4 * pr, (float)p.Y - 2 * pr); var p2 = new PointF((float)p.X + 4 * pr, (float)p.Y - 2 * pr); var p3 = new PointF((float)p.X, (float)p.Y - 4 * pr); bufferG.DrawPolygon(node.Selected ? penChoosed : pen, new PointF[] { p1, p2, p3 }); var whiteRect = new RectangleF(rectangle.X - 4 * pr, rectangle.Y - 4 * pr, rectangle.Width + 8 * pr, rectangle.Height + 8 * pr); bufferG.FillEllipse(whiteBrush, whiteRect); whiteRect = new RectangleF(rectangle.X - 4 * pr, rectangle.Y - 4 * pr, rectangle.Width + 8 * pr, rectangle.Height + 8 * pr); bufferG.DrawEllipse(node.Selected ? penChoosed : pen, whiteRect); } } } //绘制辅助线 void DrawH(Graphics bufferG, Template template) { 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 == MapViewEnum.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; if (mapOption.IsOrtho) { var wPos = GetZZWorldPoint(_select_junction1.Position3D, _MousePosition, new Vector3(1, 1, 0)); //getPointAndHeight(e, _select_junction1, out p, out z); var mapPos = WorldPointToMapPoint(wPos); bufferG.DrawLine(pen, WorldPointToMapPoint(_select_junction1), mapPos); } else { bufferG.DrawLine(pen, WorldPointToMapPoint(_select_junction1), _MousePosition); } } } } if (_isDrawingPolygon && polygonPoints.Count > 0) { List 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 pf = new List { oldP, newP }; using (var pen = new Pen(Color.Black, 1 * r)) { // 绘制多边形虚线边框 pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; bufferG.DrawLines(pen, pf.ToArray()); } } } #region 基础坐标转换方法 /// 将屏幕坐标转换为世界坐标。输入屏幕坐标 (x,y),返回世界坐标 (wx, wy)。 /// private PointF ScreenToVMap(PointF screenPos, float z = 0) { var centerX = this.map.Width / 2; var centerY = this.map.Height / 2; var worldX = (screenPos.X - centerX - Z(z).X) / Zoom.X + MapCenter.X; var worldY = (screenPos.Y - centerY) / Zoom.Y + 0; return new PointF(worldX, worldY); } /// 将屏幕坐标转换为世界坐标。输入屏幕坐标 (x,y),返回世界坐标 (wx, wy)。 /// private PointF ScreenToMap(PointF screenPos, float z = 0) { var centerX = this.map.Width / 2; var centerY = this.map.Height / 2; var worldX = (screenPos.X - centerX - Z(z).X) / Zoom.X + MapCenter.X; var worldY = (screenPos.Y - centerY - Z(z).Y) / Zoom.Y + MapCenter.Y; return new PointF(worldX, worldY); } /// 世界投影坐标转换为屏幕坐标 private PointF MapToScreen(PointF mapPos, float z = 0) { var centerX = this.map.Width / 2; var centerY = this.map.Height / 2; var screenX = (mapPos.X - MapCenter.X) * Zoom.X + centerX + Z(z).X; var screenY = (mapPos.Y - MapCenter.Y) * Zoom.Y + centerY + Z(z).Y; //if (is3Dview) screenY = -(mapPos.Y - center.Y) * (0.5f * zoom) + centerY - 2 * z; return new PointF(screenX, screenY); } // 根据旋转角度计算旋转后的坐标 private PointF Get平面旋转Point(PointF p, PointF MapC) { PointF center = MapC; double radian = Rotation * Math.PI / 180;// 角度转弧度 float x = (float)(Math.Cos(radian) * (p.X - center.X) - Math.Sin(radian) * (p.Y - center.Y) + center.X); float y = (float)(Math.Sin(radian) * (p.X - center.X) + Math.Cos(radian) * (p.Y - center.Y) + center.Y); return new PointF(x, y); } private PointF Get平面还原Point(PointF p, PointF MapC) { PointF center = MapC; double radian = -Rotation * Math.PI / 180;// 角度转弧度 float x = (float)(Math.Cos(radian) * (p.X - center.X) - Math.Sin(radian) * (p.Y - center.Y) + center.X); float y = (float)(Math.Sin(radian) * (p.X - center.X) + Math.Cos(radian) * (p.Y - center.Y) + center.Y); return new PointF(x, y); } private PointF Get俯视角旋转Point(PointF p, float z, PointF MapC) { PointF center = MapC; double radian_fushi = 俯视弧度; float sin = (float)Math.Sin(radian_fushi); float cos = (float)Math.Cos(radian_fushi); float x = (float)p.X; float y = (float)(sin * (p.Y - center.Y) + center.Y) + cos * z; return new PointF(x, y); } private PointF Get俯视角还原Point(PointF p, float z, PointF MapC) { PointF center = MapC; double radian_fushi = 俯视弧度; float sin = (float)Math.Sin(radian_fushi); float cos = (float)Math.Cos(radian_fushi); float x = (float)p.X; float y = (p.Y - center.Y - cos * z) / sin + center.Y; return new PointF(x, y); } private PointF GetRotateVector(PointF p, PointF p0) { double radian = Rotation * Math.PI / 180;// 角度转弧度 float x = (float)(Math.Cos(radian) * (p.X - p0.X) - Math.Sin(radian) * (p.Y - p0.Y)); float y = (float)(Math.Sin(radian) * (p.X - p0.X) + Math.Cos(radian) * (p.Y - p0.Y)); return new PointF(x, y); } /// 获取世界投影坐标 private PointF WorldPointToMapPoint(PointF point, float z, PointF3D offset = null) { if (offset == null) offset = new PointF3D(0, 0, 0); point = new PointF(point.X + offset.X, point.Y + offset.Y); var pointR = Get平面旋转Point(point, MapCenter); var pointT = Get俯视角旋转Point(pointR, z + offset.Z, MapCenter); //var n=new PointF((float)pointR.X - Z(z).X, (float)(pointR.Y - Z(z).Y)); return pointT; } private PointF WorldPointToMapPoint(PointF3D point, PointF3D offset = null) { return WorldPointToMapPoint(new PointF(point.X, point.Y), point.Z, offset); } private PointF WorldPointToMapPoint(NodeViewModel junction, PointF3D offset = null) { PointF p; if (junction == null) return new PointF(0, 0); p = WorldPointToMapPoint(junction.Position, junction.Elev, offset); return p; } private PointF CubeWorldPointToMapPoint(NodeViewModel junction, PointF3D offset = null) { if (junction == null) return new PointF(0, 0); var point = junction.Position; var z = junction.Elev; if (offset == null) offset = new PointF3D(0, 0, 0); point = new PointF(point.X + offset.X, point.Y + offset.Y); var pointR = Get平面旋转Point(point, new PointF(0, 0)); var pointT = Get俯视角旋转Point(pointR, z + offset.Z, new PointF(0, 0)); return pointT; } private List WorldPointToMapPoint(LinkViewModel pipe, PointF3D offset = null) { List list = new List(); PointF p; p = WorldPointToMapPoint(pipe.StartNode, offset); list.Add(p); p = WorldPointToMapPoint(pipe.EndNode, offset); list.Add(p); return list; } /// 获取正交投影坐标,返回的是世界坐标 /// 世界坐标 /// 地图坐标 /// 投影向量 /// private PointF3D GetZZWorldPoint(PointF3D position3D, PointF mousePosition, Vector3 vector3) { //做一条通过position3D的平行于vector3的直线, if (vector3 == new Vector3(0, 0, 1)) { return GetLGWorldPoint(position3D, mousePosition); } else { var p2 = MapPointToWorldPoint(mousePosition, position3D.Z); var vector = new Vector2(p2.X - position3D.X, p2.Y - position3D.Y); //判断二维向量vector在第几象限,距离哪个轴最近 var x = vector.X; var y = vector.Y; var x1 = Math.Abs(x); var y1 = Math.Abs(y); if (x1 > y1) { if (x > 0) { //第一象限 return new PointF3D(position3D.X + Math.Abs(x), position3D.Y, position3D.Z); } else { //第三象限 return new PointF3D(position3D.X - Math.Abs(x), position3D.Y, position3D.Z); } } else { if (y > 0) { //第二象限 return new PointF3D(position3D.X, position3D.Y + Math.Abs(y), position3D.Z); } else { //第四象限 return new PointF3D(position3D.X, position3D.Y - Math.Abs(y), position3D.Z); } } } } /// 获取正交投影坐标,返回的是世界坐标 /// 世界坐标 /// 地图坐标 /// 投影向量 /// private PointF3D GetLGWorldPoint(PointF3D position3D, PointF p2) { double radian_fushi = 俯视弧度; float sin = (float)Math.Sin(radian_fushi); float cos = (float)Math.Cos(radian_fushi); var p1 = WorldPointToMapPoint(position3D); var dy = p2.Y - p1.Y; float dz = dy / cos; return new PointF3D(position3D.X, position3D.Y, position3D.Z + dz); } private PointF MapPointToWorldPoint(PointF3D point) { return MapPointToWorldPoint(new PointF(point.X, point.Y), point.Z); } /// 获取地图投影坐标 /// /// public PointF MapPointToWorldPoint(PointF point, float z = 0) { var pointT = Get俯视角还原Point(point, z, MapCenter); pointT = Get平面还原Point(pointT, MapCenter); //var n=new PointF((float)pointR.X - Z(z).X, (float)(pointR.Y - Z(z).Y)); return pointT; } private PointF GetMapPoint_还原(NodeViewModel junction) { PointF p; p = MapPointToWorldPoint(junction.Position, junction.Elev); return p; } #endregion #region 计算三维相机 public PointF3D GetCameraPosition(float distance = 1) { // 将角度转换为弧度 float rotationRadians = (float)Rotation * (float)Math.PI / 180; float rotationFRadians = (float)RotationF * (float)Math.PI / 180; // 计算相机的球坐标系位置 float x = distance * (float)Math.Sin(rotationFRadians) * (float)Math.Cos(rotationRadians); float y = distance * (float)Math.Sin(rotationFRadians) * (float)Math.Sin(rotationRadians); float z = distance * (float)Math.Cos(rotationFRadians); return new PointF3D(x, y, z); } public bool IsFaceVisibleToCamera(AreaViewModel area, PointF3D cameraPosition) { //正面是2,右面是1,左面是3,背面是4 //Rotation为0时,只显示正面,Rotation为90时,只显示右面,Rotation为180时,只显示背面,Rotation为270时,只显示左面 int delta = 5; bool flag = false; switch (area.Name) { case "左": //Rotation为0~180时显示 if (RotationF <= 90 - delta && Rotation >= 0 + delta && Rotation <= 180 - delta) flag = true; break; case "前": //Rotation为0~180时显示 if (RotationF <= 90 - delta && Rotation >= -90 + delta && Rotation <= 90 - delta) flag = true; break; case "右": //Rotation为0~180时显示 if (RotationF <= 90 - delta && Rotation >= -180 + delta && Rotation <= 0 - delta) flag = true; break; case "后": //Rotation为0~180时显示 if (RotationF <= 90 - delta && ((Rotation >= 90 + delta && Rotation <= 180) || (Rotation >= -180 && Rotation <= -90 - delta))) flag = true; break; case "上": if (RotationF >= 0 + delta) flag = true; break; case "下": if (RotationF <= 0 - delta) flag = true; break; } return flag; } #endregion #region 判断可见性 private float Get_dist(PointF A, PointF B) { float dx = A.X - B.X; float dy = A.Y - B.Y; float dist = (float)Math.Sqrt(dx * dx + dy * dy); return dist; } //判断A距离线段B和C的距离,如果超出了线段的范围,则返回到最近的端点的距离;距离线段中心点越远,返回的距离越大; private float Get_dist(PointF A, PointF B, PointF C, float MaxOff) { //PointF A, PointF B,PointF C,求点A到B、C构成线段的中心点的距离 float dist_off = GetDistanceFromPointAToMidpointOfLineSegmentBC(A, B, C); //使用dist_off 跟 线段A、B的长度比较,如果大于1/2,则返回MaxOff,否则按照比例返回 float dist_len = Get_dist(B, C); if (dist_len < 5) dist_len = 5; float dist_add = (dist_off / dist_len > 0.5 ? MaxOff : dist_off / dist_len * 2 * MaxOff); float dx = C.X - B.X; float dy = C.Y - B.Y; float dist = (float)Math.Sqrt(dx * dx + dy * dy); if (dist == 0) return Get_dist(A, B) + dist_add; float t = ((A.X - B.X) * dx + (A.Y - B.Y) * dy) / (dist * dist); if (t < 0) return Get_dist(A, B) + dist_add; if (t > 1) return Get_dist(A, C) + dist_add; float x = B.X + t * dx; float y = B.Y + t * dy; return Get_dist(A, new PointF(x, y)) + dist_add; } private float GetDistanceFromPointAToMidpointOfLineSegmentBC(PointF A, PointF B, PointF C) { // Calculate the midpoint of the line segment BC PointF midpoint = new PointF((B.X + C.X) / 2, (B.Y + C.Y) / 2); // Calculate the distance from point A to the midpoint float dx = midpoint.X - A.X; float dy = midpoint.Y - A.Y; float distance = (float)Math.Sqrt(dx * dx + dy * dy); return distance; } PointF PMin_Show, PMax_Show; /// 判断是否在屏幕坐标内 /// public bool isVisible(PointF MapPos) { if (MapPos.X < PMin_Show.X || MapPos.X > PMax_Show.X || MapPos.Y < PMin_Show.Y || MapPos.Y > PMax_Show.Y) return false; else return true; } /// 判断是否在屏幕坐标内 /// public bool isVisible(List list_MapPos) { bool visible = false; foreach (var MapPos in list_MapPos) { if (MapPos.X < PMin_Show.X || MapPos.X > PMax_Show.X || MapPos.Y < PMin_Show.Y || MapPos.Y > PMax_Show.Y) { } else { visible = true; return true; } } return visible; } #endregion } public partial class MapViewer { #region 核心属性 TContainer TC = new TContainer(); /// 地图选项 public MapDimensions mapOption { get { return TC.mapOption; } set { TC.mapOption = value; } } /// 地图选项_起始操作时 private MapDimensions mapOption0 = new MapDimensions(); /// 临时管网层 public Template _newTemplate { get { return TC.newTemplate; } set { TC.newTemplate = value; } } public Template _Template { get { return TC.template; } set { TC.template = value; label_file.Text = TC.template?.filePath; } } #endregion #region 交互属性 /// 悬停对象 private List hoveredObjs = new List(); /// 选中对象 public List selectedObjs = new List(); private List selectedNodes => selectedObjs.FindAll(o => o is NodeViewModel).Select(o => (NodeViewModel)o).ToList(); private List selectedLinks => selectedObjs.FindAll(o => o is LinkViewModel).Select(o => (LinkViewModel)o).ToList(); MouseState _mouseState = MouseState.无; private NodeViewModel _OperaNode = null; public PointF mouseXY = new PointF(0, 0); PointF DragStartPos; PointF _ClickStartPos; PointF RotaStartPos; PointF BackGroudPicLeftPos; bool _isPanning; /// 拖拽选择 bool _isDragging; bool _isRotating; bool _isPainting; PointF mousePosition; // control+鼠标中间按下缩放 bool _isInsertingObject = false; bool _isMovingObject = false; bool _isPastingObject = false; Cursor _lastCursor; object _undoOldValue = null; private List polygonPoints = new List(); private bool _isDrawingPolygon; #endregion #region 新增管网(辅助) MapViewNetWork _NewNet { get { if (_newTemplate == null) _newTemplate = new Template(); if (_newTemplate.network == null) _newTemplate.network = new MapViewNetWork(); return _newTemplate.network; } } #endregion #region 显示选项(辅助) private string _StartPoint = null; private string _EndPoint = null; //private bool __isEditMode = true; public bool _IsEditMode { get { return this.mapOption?.isEditMode ?? true; } set { toolStripComboBox_浏览模式.Text = value ? "编辑模式" : "浏览模式"; if (this.mapOption != null) this.mapOption.isEditMode = value; 转换为ToolStripMenuItem.Visible = _IsEditMode; toolStripSeparator9.Visible = _IsEditMode; 删除ToolStripMenuItem.Visible = _IsEditMode; 删除ToolStripMenuItem1.Visible = _IsEditMode; 复制ToolStripMenuItem.Visible = _IsEditMode; 复制ToolStripMenuItem1.Visible = _IsEditMode; 粘贴ToolStripMenuItem.Visible = _IsEditMode; 粘贴ToolStripMenuItem1.Visible = _IsEditMode; 设置长度ToolStripMenuItem.Visible = _IsEditMode; 设为关闭ToolStripMenuItem.Visible = _IsEditMode; 设为立管点ToolStripMenuItem.Visible = _IsEditMode; 对齐ToolStripMenuItem.Visible = _IsEditMode; 对齐ToolStripMenuItem1.Visible = _IsEditMode; toolStripButton_新建节点.Enabled = _IsEditMode; toolStripButton_新建管线.Enabled = _IsEditMode; toolStripButton_新建立管.Enabled = _IsEditMode; toolStripButton_添加水库.Enabled = _IsEditMode; toolStripButton_添加水池.Enabled = _IsEditMode; toolStripButton_添加水表.Enabled = _IsEditMode; toolStripButton_添加阀门.Enabled = _IsEditMode; toolStripButton_重复器.Enabled = _IsEditMode; } } public float Link_multiply { get { if (_Template == null || _Template.mapOption == null) return 1.0f; return _Template.mapOption.Link_multiply; } set { if (_Template == null || _Template.mapOption == null) return; _Template.mapOption.Link_multiply = value; } } public float junction_multiply { get { if (_Template == null || _Template.mapOption == null) return 1.0f; return _Template.mapOption.junction_multiply; } set { if (_Template == null || _Template.mapOption == null) return; _Template.mapOption.junction_multiply = value; } } [DisplayName("显示阀门")] public bool _ShowValve { get { if (_Template == null || _Template.mapOption == null) return true; return _Template.mapOption._ShowValve; } set { if (_Template == null || _Template.mapOption == null) return; _Template.mapOption._ShowValve = value; } } [DisplayName("显示节点")] public bool _ShowJunction { get { if (_Template == null || _Template.mapOption == null) return true; return _Template.mapOption._ShowJunction; } set { if (_Template == null || _Template.mapOption == null) return; _Template.mapOption._ShowJunction = value; } } string _filePath { get { if (string.IsNullOrEmpty(_Template?.filePath)) return null; string path = _Template.filePath.TrimStart('\\'); return Path.Combine(Directory.GetCurrentDirectory(), path); } //set //{ //_Template.路径 = value; //} } private MapViewNetWork _Network { get { return _Template?.network; } } #endregion #region 管网属性(辅助) public List _Nodes { get { return _Network?.Nodes ?? new List(); } } public List _Links { get { return _Network?.Links ?? new List(); } } private List _areas = new List(); public List _Areas { get { return _areas; } } #endregion #region 视角设置(辅助) private const float MinZoom = 0.1f; private const float MaxZoom = 1000.0f; [DisplayName("缩放系数")] public float zoom { get { return mapOption.zoom; } set { label_zoom.Text = $"Zoom:{zoom.ToString("0.000")}"; mapOption.zoom = value; } } [DisplayName("旋转角度")] public double Rotation { get { return mapOption.rotation; } set { toolStripStatusLabel_rotation.Text = $"Rotation:({Rotation.ToString("0")},{RotationF.ToString("0")})"; //将旋转角度转换为-180~180 value = value % 360; if (value > 180) value -= 360; else if (value < -180) value += 360; mapOption.rotation = value; } } private double Rotation0 = 0; public PointF MapCenter { get { return mapOption.Center; } set { label_center.Text = $"center:({MapCenter.X.ToString("0.00")} ,{MapCenter.Y.ToString("0.00")})"; mapOption.Center = value; } } private PointF MapCenter0; private bool is3Dview = false; double 俯视角度_start = 90; public bool Lock2DView { get { return mapOption.Lock2DView; } set { mapOption.Lock2DView = value; } } /// 俯视线与底面的夹角,投影用sin [DisplayName("俯视角度")] public double RotationF { get { return mapOption.rotationF; } set { mapOption.rotationF = value; } } public double 俯视弧度 { get { return RotationF / 180 * Math.PI; } } public PointF Zoom { get { return new PointF(zoom, -zoom); } } private PointF Z(float z) { return new PointF(0, 0); } #endregion #region 颜色分级(辅助) public Colour NodeColour { set { var type = value.Type; value.isChoosed = true; _Template?.Colours?.RemoveAll(cl => cl.Type == type); _Template.Colours.Add(value); mapOption.ColourNode = type; } private get { return _Template?.Colours?.FirstOrDefault(cl => cl.isChoosed && cl.Type == mapOption.ColourNode); } } public Colour LinkColour { set { var type = value.Type; value.isChoosed = true; _Template?.Colours?.RemoveAll(cl => cl.Type == type); _Template.Colours.Add(value); mapOption.ColourLink = type; } private get { return _Template?.Colours?.FirstOrDefault(cl => cl.isChoosed && cl.Type == mapOption.ColourLink); } } //private bool __isOrtho = true; #endregion #region 正交模式 private bool _isOrtho { get { return mapOption.IsOrtho; } set { mapOption.IsOrtho = value; if (mapOption.IsOrtho) { label_ZZ.Text = "正交模式:开"; } else { label_ZZ.Text = "正交模式:关"; } } } #endregion #region 事件 //按帧数判断是否重绘,减少计算量(每帧最多重绘一次) bool _timerDraw = false; //按帧数判断鼠标悬停对象,减少计算量(每帧最多判断一次) bool _mouseHoverCheckFlag = false; #endregion } /// /// 几何计算辅助类 class GraphHelper { public static Color getNodeColor(Colour colour, NodeViewModel node) { double value = 0; Color color = Color.Gray; switch (colour.Type) { case ColourType.节点自由压力: value = node.EN_PRESSURE; break; case ColourType.节点绝对压力: value = node.EN_HEAD; break; case ColourType.节点需水量: value = node.EN_DEMAND; break; } for (int i = 0; i < colour.Items.Count; i++) { if (colour.Items[i].DRange.IsInside(value)) { color = colour.Items[i].value; break; } } return color; } public static Color getLinkColor(Colour colour, LinkViewModel link) { double value = 0; Color color = Color.Gray; switch (colour.Type) { case ColourType.管线流量: value = link.EN_FLOW; break; case ColourType.管线流速: value = link.EN_VELOCITY; break; } for (int i = 0; i < colour.Items.Count; i++) { if (colour.Items[i].DRange.IsInside(value)) { color = colour.Items[i].value; break; } } return color; } public static long GetUlongByPoint(PointF ps, float delta = 20, int MaxY = 2000) { return (long)((int)(ps.X / delta) + ((int)Math.Round(ps.Y / delta)) * MaxY / delta); } public static List Get等分Nodes(PointF p1, PointF p2, int n) { // 计算线段长度 float len = (float)Math.Sqrt(Math.Pow(p2.X - p1.X, 2) + Math.Pow(p2.Y - p1.Y, 2)); if (len == 0) len = 0.00001f; // 计算单位向量 PointF u = new PointF((p2.X - p1.X) / len, (p2.Y - p1.Y) / len); // 计算间距 float d = len / (n + 1); // 计算n等分点 List nodes = new List(); for (int i = 1; i < n + 1; i++) { PointF node = new PointF(p1.X + i * d * u.X, p1.Y + i * d * u.Y); if (node.X == float.NaN || node.Y == float.NaN) node = p1; nodes.Add(node); } return nodes; } public static PointF getRotatePoint(float px, float py, PointF center, PointF x, PointF y) { PointF p = new PointF(px, py); return getRotatePoint(p, center, x, y); } private static PointF getRotatePoint(PointF p, PointF center, PointF x, PointF y) { float angle = (float)Math.Atan2(y.Y - x.Y, y.X - x.X); float distance = (float)Math.Sqrt(Math.Pow(p.X - center.X, 2) + Math.Pow(p.Y - center.Y, 2)); float rotationAngle = (float)(Math.Atan2(p.Y - center.Y, p.X - center.X) + angle); float rotatedX = center.X + distance * (float)Math.Cos(rotationAngle); float rotatedY = center.Y + distance * (float)Math.Sin(rotationAngle); return new PointF(rotatedX, rotatedY); } } public class Prompt : Form { private static TextBox textBox; private static Button okButton; public static string ShowDialog(string text, string caption, string defaultTxt = "") { Form prompt = new Form() { Width = 200, Height = 150, FormBorderStyle = FormBorderStyle.FixedDialog, Text = caption, StartPosition = FormStartPosition.CenterScreen }; Label textLabel = new Label() { Left = 20, Top = 20, Text = text }; textBox = new TextBox() { Left = 20, Top = 50, Width = 150 }; textBox.Text = defaultTxt; okButton = new Button() { Text = "确定", Left = 75, Width = 75, Top = 80 }; okButton.Click += (sender, e) => { prompt.Close(); }; prompt.Controls.Add(textBox); prompt.Controls.Add(textLabel); prompt.Controls.Add(okButton); prompt.ShowDialog(); return textBox.Text; } } public class GlobalObject { public static PropertyForm PropertyForm; public static MapViewer map; public static bool LockSelect = false; public static bool ApplyFilter = false; } partial class empty { } //定义一个委托,用来存储void Draw(Graphics bufferG, Template template) public delegate void DrawDelegate(Graphics bufferG, Template template); public delegate void MouseDelegate(MouseEventArgs e); public class TContainer { public MapDimensions mapOption = new MapDimensions(); public Template newTemplate = null; public Template template = null; } public class Area : BaseModel, IBaseViewModel { public List Points { get; set; } public bool Selected { get; set; } [Description("鼠标悬于上方")] [DisplayName("鼠标悬于上方")] public bool Hovered { get; set; } [DisplayName("位置信息")] public PointF Position { get; set; } = new PointF(0, 0); public String regionName { get; set; } = null; [Description("X坐标")] [DisplayName("X坐标")] [Browsable(true)] public float X { get { return Position.X; } set { Position = new PointF(value, Position.Y); } } [Description("Y坐标")] [DisplayName("Y坐标")] [Browsable(true)] public float Y { get { return Position.Y; } set { Position = new PointF(Position.X, value); } } [Description("标高")] [DisplayName("标高")] [Browsable(true)] public float Elev { get; set; } [Description("对象的等级")] [DisplayName("级别")] public int Level { get; set; } = 0; [Description("对象的等级")] [DisplayName("是否显示")] public bool Visible { get; set; } = true; public MapObjectType Type { get { return this.GetTypeString(); } } [Description("ID类型")] [DisplayName("ID类型")] public string IDType => Type.ToString() + "\t" + ID; [Description("标签")] [DisplayName("标签")] [Editor(typeof(MyEditor), typeof(UITypeEditor))] public TagList Tags { get; set; } = null; public MapObjectType GetTypeString() { if (this is JunctionViewModel) return MapObjectType.节点; if (this is ReservoirViewModel) return MapObjectType.水库; if (this is TankViewModel) return MapObjectType.水池; if (this is MeterViewModel) return MapObjectType.水表; if (this is NozzleViewModel) return MapObjectType.喷头; if (this is ValveNodeViewModel) return MapObjectType.阀门点; if (this is PipeViewModel) return MapObjectType.管线; if (this is ValveViewModel) return MapObjectType.阀门; if (this is RepeaterViewModel) return MapObjectType.重复器; if (this is PumpViewModel) return MapObjectType.水泵; if (this is PumpNodeViewModel) return MapObjectType.水泵点; return MapObjectType.节点; } public bool isNode() { if (this is JunctionViewModel) return true; if (this is ReservoirViewModel) return true; if (this is TankViewModel) return true; if (this is MeterViewModel) return true; if (this is NozzleViewModel) return true; return false; } } public interface IBaseViewModel { [Description("对象的ID唯一标识")] [DisplayName(" 编号 ")] string ID { get; set; } bool Selected { get; set; } bool Hovered { get; set; } [DisplayName("位置信息")] PointF Position { get; set; }//= new PointF(0, 0); String regionName { get; set; }//= null; [Description("X坐标")] [DisplayName("X坐标")] [Browsable(true)] float X { get; set; } //{ //get //{ //return Position.X; //} //set //{ //Position = new PointF(value, Position.Y); //} //} [Description("Y坐标")] [DisplayName("Y坐标")] [Browsable(true)] float Y { get; set; } //{ //get //{ //return Position.Y; //} //set //{ //Position = new PointF(Position.X, value); //} //} [Description("标高")] [DisplayName("标高")] [Browsable(true)] float Elev { get; set; } [Description("对象的等级")] [DisplayName("级别")] //[Editor(typeof(MyPropertyEditor), typeof(UITypeEditor))] int Level { get; set; } //= 0; [Description("对象的等级")] [DisplayName("是否显示")] bool Visible { get; set; } //= true; // //[Description("标签集合")] //[DisplayName("标签")] //public string Tags { get; set; } = null; MapObjectType Type { get; }// { get { return this.GetTypeString(); } } // [Description("ID类型")] [DisplayName("ID类型")] string IDType { get; }// => Type.ToString()+"\t"+ ID; MapObjectType GetTypeString(); TagList Tags { get; set; } //string TagsString { get; set; } bool isNode(); } public class TagList : List { public override string ToString() { if (Count == 0) return "null"; else return string.Join(",", this); } //public TagList(string value):base(value.Split(',')) //{ //if (string.IsNullOrEmpty(value) || value == "null") //{ //base.Clear(); //return; //} //} public TagList() { } public TagList(string value) { if (string.IsNullOrEmpty(value) || value == "null") { base.Clear(); return; } string[] tags = value.Split(','); base.AddRange(tags); } } public class MyEditor : UITypeEditor { public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { return UITypeEditorEditStyle.Modal; } public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { List tags = value as List; // Create and show dialog TagEditorForm form = new TagEditorForm(tags); //form弹出时,位置在鼠标位置 form.StartPosition = FormStartPosition.Manual; form.Location = new Point(Cursor.Position.X - form.Width + 10, Cursor.Position.Y - 10); //if (form.ShowDialog() == DialogResult.OK) //{ //} form.ShowDialog(); return form.Tags; //return base.EditValue(context, provider, value); } } public class TagEditorForm : Form { public List Tags { get; set; } private ListBox listBox; private TextBox tb_text; public TagEditorForm(List tags) { Tags = tags; // Initialize ListBox listBox = new ListBox(); listBox.DataSource = Tags; listBox.Dock = DockStyle.Fill; this.Controls.Add(listBox); // Add buttons for add, remove, update operations tb_text = new TextBox(); tb_text.Dock = DockStyle.Top; this.Controls.Add(tb_text); Button addButton = new Button(); addButton.Dock = DockStyle.Bottom; addButton.Text = "添加"; addButton.Click += AddButton_Click; this.Controls.Add(addButton); Button removeButton = new Button(); removeButton.Dock = DockStyle.Bottom; removeButton.Text = "删除"; removeButton.Click += RemoveButton_Click; this.Controls.Add(removeButton); Button updateButton = new Button(); updateButton.Dock = DockStyle.Bottom; updateButton.Text = "更新"; updateButton.Click += UpdateButton_Click; this.Controls.Add(updateButton); Panel panel = new Panel(); updateButton.Dock = DockStyle.Bottom; this.Controls.Add(panel); Button btn_ok = new Button(); btn_ok.Dock = DockStyle.Left; btn_ok.Click += (o, e) => { this.DialogResult = DialogResult.OK; }; btn_ok.Text = "确定"; panel.Controls.Add(btn_ok); Button btn_cancel = new Button(); btn_cancel.Dock = DockStyle.Right; btn_ok.Click += (o, e) => { this.DialogResult = DialogResult.Cancel; }; btn_cancel.Text = "取消"; panel.Controls.Add(btn_cancel); listBox.SelectedIndexChanged += (o, e) => { if (listBox.SelectedItem != null) tb_text.Text = listBox.SelectedItem.ToString(); }; this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); } private void AddButton_Click(object sender, EventArgs e) { // 在listBox中按tb_text的内容,添加新的tag if (tb_text.Text != null && tb_text.Text != "") { if (Tags == null) Tags = new List(); Tags.Add(tb_text.Text); listBox.DataSource = null; listBox.DataSource = Tags; } } private void RemoveButton_Click(object sender, EventArgs e) { //删除listBox中选中的tag if (listBox.SelectedItem != null) { Tags.Remove(listBox.SelectedItem.ToString()); listBox.DataSource = null; listBox.DataSource = Tags; } // Remove tag } private void UpdateButton_Click(object sender, EventArgs e) { // 在listBox中按tb_text的内容,更新tag,但是不改变顺序 if (listBox.SelectedItem != null) { Tags[listBox.SelectedIndex] = tb_text.Text; listBox.DataSource = null; listBox.DataSource = Tags; } } } public class LinkViewModel : LinkCalcModel, IBaseViewModel { #region 构造函数 public LinkViewModel() { } public LinkViewModel(PointF startPoint, PointF endPoint) { StartNode = new NodeViewModel(startPoint); EndNode = new NodeViewModel(endPoint); } public LinkViewModel(PointF startPoint, PointF endPoint, List points) { StartNode = new NodeViewModel(startPoint); EndNode = new NodeViewModel(endPoint); } #endregion #region 属性 [DisplayName("编号")] [Browsable(true)] public new string ID { get { return base.ID; } set { base.ID = value; } } [DisplayName("名称")] [Browsable(true)] public new string Name { get { return base.Name; } set { base.Name = value; } } [DisplayName("起始节点")] [Browsable(true)] public string Node1 { get { return base.Node1; } set { base.Node1 = value; } } [DisplayName("终止节点")] [Browsable(true)] public string Node2 { get { return base.Node2; } set { base.Node2 = value; } } public NodeViewModel StartNode { get { return (NodeViewModel)base.StartNode; } set { base.StartNode = value; } } public NodeViewModel EndNode { get { return (NodeViewModel)base.EndNode; } set { base.EndNode = value; } } private PointF _position { get; set; } = new PointF(0, 0); public PointF Position { get { { if (StartNode == null || EndNode == null) return _position; var x = (StartNode.Position.X + EndNode.Position.X) / 2; var y = (StartNode.Position.Y + EndNode.Position.Y) / 2; _position = new PointF(x, y); } return _position; } set { } } public List Points { get { return new List() { StartNode.Position, EndNode.Position }; } } public PointF[] ToArray(bool is3Dview = false) { if (!is3Dview) return new PointF[] { new PointF((float)(StartNode.X), (float)(StartNode.Y)), new PointF((float)(EndNode.X), (float)(EndNode.Y)) }; else return new PointF[] { new PointF((float)(StartNode.X), (float)(StartNode.Y - 2 * StartNode.Elev)), new PointF((float)(EndNode.X), (float)(EndNode.Y - 2 * EndNode.Elev)) }; } [DisplayName("标高(m)")] public float Elev { get { if (StartNode == null || EndNode == null) return 0; return (StartNode.Elev + EndNode.Elev) / 2; } set { } } [Category("计算参数")] [DisplayName("初始状态")] [Browsable(true)] public StatusType Status { get { return base.Status; } set { base.Status = value; } } [DisplayName("口径(mm)")] [Browsable(true)] public new float Diameter { get { return base.Diameter; } set { base.Diameter = value; } } [DisplayName("长度(m)")] [Browsable(true)] /// 长度 public float Length { get { return base.Length; } set { base.Length = value; } } public String regionName { get; set; } = null; [Description("X坐标")] [DisplayName("X坐标")] [Browsable(true)] public float X { get { return Position.X; } set { } } [Description("Y坐标")] [DisplayName("Y坐标")] [Browsable(true)] public float Y { get { return Position.Y; } set { } } [Description("对象的等级")] [DisplayName("级别")] public int Level { get; set; } = 0; [Description("对象的等级")] [DisplayName("是否显示")] public bool Visible { get; set; } = true; [Description("标签")] [DisplayName("标签")] [Editor(typeof(MyEditor), typeof(UITypeEditor))] public TagList Tags { get; set; } = null; public MapObjectType Type { get { return this.GetTypeString(); } } [Description("ID类型")] [DisplayName("ID类型")] #endregion #region 方法 public string IDType => Type.ToString() + "\t" + ID; public MapObjectType GetTypeString() { if (this is JunctionViewModel) return MapObjectType.节点; if (this is ReservoirViewModel) return MapObjectType.水库; if (this is TankViewModel) return MapObjectType.水池; if (this is MeterViewModel) return MapObjectType.水表; if (this is NozzleViewModel) return MapObjectType.喷头; if (this is ValveNodeViewModel) return MapObjectType.阀门点; if (this is PipeViewModel) return MapObjectType.管线; if (this is ValveViewModel) return MapObjectType.阀门; if (this is RepeaterViewModel) return MapObjectType.重复器; if (this is PumpViewModel) return MapObjectType.水泵; if (this is PumpNodeViewModel) return MapObjectType.水泵点; return MapObjectType.节点; } public bool isNode() { if (this is JunctionViewModel) return true; if (this is ReservoirViewModel) return true; if (this is TankViewModel) return true; if (this is MeterViewModel) return true; if (this is NozzleViewModel) return true; return false; } #endregion } public class NodeViewModel : NodeCalcModel, IBaseViewModel { #region 构造函数 public NodeViewModel() { } public NodeViewModel(PointF position) { Position = position; } public NodeViewModel(int X, int Y) { Position = new PointF(X, Y); } #endregion #region 属性 [DisplayName("编号")] [Browsable(true)] public new string ID { get { return base.ID; } set { base.ID = value; } } [DisplayName("名称")] [Browsable(true)] public new string Name { get { return base.Name; } set { base.Name = value; } } public PointF3D Position3D { get { return new PointF3D(X, Y, Elev); } set { Position = new PointF(value.X, value.Y); Elev = value.Z; } } [Description("X坐标")] [DisplayName("X坐标")] [Browsable(true)] public new float X { get { return base.X; } set { base.X = value; } } [Description("Y坐标")] [DisplayName("Y坐标")] [Browsable(true)] public new float Y { get { return base.Y; } set { base.Y = value; } } [Description("标高(m)")] [DisplayName("标高(m)")] [Browsable(true)] public new float Elev { get { return base.Elev; } set { base.Elev = value; } } public MapObjectType Type { get { return this.GetTypeString(); } } [Category("计算参数")] [Description("最大口径(mm)")] [DisplayName("最大口径(mm)")] public virtual float MaxDiameter { get; set; } = 0; [Category("计算参数")] [Description("需水量(m³/h)")] [DisplayName("需水量(m³/h)")] [Browsable(true)] public virtual float Demand { get; set; } /// 模式的编号 [Category("计算参数")] [Description("用水量模式的编号")] [DisplayName("模式编号")] [Browsable(true)] public virtual string PatternID { get; set; } [DisplayName("链表清单")] [Browsable(true)] public List Links { get { return base.Links; } set { base.Links = value; } } public List ViewLinks { get { return base.Links.Select(oo => oo as LinkViewModel).ToList(); } } [DisplayName("位置信息")] public PointF Position { get { return new PointF(X, Y); } set { if (value != null) X = value.X; Y = value.Y; } } [Description("标签")] [DisplayName("标签")] [Editor(typeof(MyEditor), typeof(UITypeEditor))] public TagList Tags { get; set; } = null; public String regionName { get; set; } = null; [Description("对象的等级")] [DisplayName("级别")] public int Level { get; set; } = 0; [Description("对象的等级")] [DisplayName("是否显示")] public bool Visible { get; set; } = true; [Description("ID类型")] [DisplayName("ID类型")] public string IDType => Type.ToString() + "\t" + ID; #endregion #region 方法 public void Move(Vector3 vector) { X += vector.X; Y += vector.Y; Elev += vector.Z; } public MapObjectType GetTypeString() { if (this is JunctionViewModel) return MapObjectType.节点; if (this is ReservoirViewModel) return MapObjectType.水库; if (this is TankViewModel) return MapObjectType.水池; if (this is MeterViewModel) return MapObjectType.水表; if (this is NozzleViewModel) return MapObjectType.喷头; if (this is ValveNodeViewModel) return MapObjectType.阀门点; if (this is PipeViewModel) return MapObjectType.管线; if (this is ValveViewModel) return MapObjectType.阀门; if (this is RepeaterViewModel) return MapObjectType.重复器; if (this is PumpViewModel) return MapObjectType.水泵; if (this is PumpNodeViewModel) return MapObjectType.水泵点; return MapObjectType.节点; } public bool isNode() { if (this is JunctionViewModel) return true; if (this is ReservoirViewModel) return true; if (this is TankViewModel) return true; if (this is MeterViewModel) return true; if (this is NozzleViewModel) return true; return false; } public string ToEmitterString() { if (this is NozzleViewModel n) { if (n.FlowCoefficient > 0) return $"{ID}\t{n.FlowCoefficient * Math.Pow(10 / 101.972, 0.5) / 1000 * 60}\r\n"; } return null; } #endregion } public static class Copy { public static T DeepCopy(this T obj) { dynamic retval; using (MemoryStream ms = new MemoryStream()) { BinaryFormatter bf = new BinaryFormatter(); //序列化成流 bf.Serialize(ms, obj); ms.Seek(0, SeekOrigin.Begin); //反序列化成对象 retval = bf.Deserialize(ms); ms.Close(); } return (T)retval; } } public class Dataset { //设置Dataset的default值 public static List listString = new List() { "流量扬程曲线", "流量功率曲线", "流量效率曲线" }; public Dataset(string name, PumpViewModel pump, int Degree = 2) { Name = name; this.pump = pump; this.degree = Degree; } public override string ToString() { StringBuilder txt = new StringBuilder(); foreach (PointF point in _data) { txt.AppendLine($"{Name}\t{point.X}\t{point.Y}"); } return txt.ToString(); } //public Dataset() //{ //} public Color Color { get { switch (Name) { case "流量扬程曲线": return Color.Blue; //break; case "流量功率曲线": return Color.Orange; //break; case "流量效率曲线": return Color.Red; //break; default: return Color.Blue; } } } public string Name { get; set; } public List _data = new List(); int FitTimes = 2; public List Data { get { if (pump == null || pump.额定转速 == 0) return _data; float eg = (float)pump.当前转速 / (float)pump.额定转速; if (eg >= 1) return _data; else { switch (Name) { case "流量扬程曲线": return _data.Select(p => { p.X *= eg; p.Y *= eg * eg; return p; }).ToList(); case "流量功率曲线": return _data.Select(p => { p.X *= eg; p.Y *= eg * eg * eg; return p; }).ToList(); case "流量效率曲线": var c1 = pump.Datasets["流量扬程曲线"]; var c2 = pump.Datasets["流量功率曲线"]; if (c1.IsFitted && c2.IsFitted && c1.Data.Count == c2.Data.Count) { List points = new List(); for (int i = 0; i < c1.Data.Count; i++) { float x = c1.Data[i].X; float y = x * c1.Data[i].Y / c2.Data[i].Y / 3.6f; points.Add(new PointF(x, y)); //功率=流量* 扬程 / 效率 / 3.6f //效率=流量* 扬程 / 功率 / 3.6f } return points; } else { return _data; } default: return _data; } } } set { IsFitted = false; _data = value; } } public int degree { get { return FitTimes; } set { if (FitTimes != value) this.IsFitted = false; FitTimes = value; } } public List ForumParams = null; public DenseVector coefficients = null; // 存储多项式系数 public static double ErrNum { get { return -1; } } public static double stepNum { get { return 800; } } private double step { get { return (range_X.Max - range_X.Min) / stepNum; } } [NonSerialized] public PumpViewModel pump = null; /// 不需要读取 public string Legend { get { switch (Name) { case "流量扬程曲线": return "Legend1"; case "流量功率曲线": return "Legend1"; case "流量效率曲线": return "Legend1"; } return "Legend1"; } } public void CurveFit() { if (!HasData) { IsFitted = false; return; } coefficients = Fit.Polynomial(Data.Select(p => (double)p.X).ToArray(), Data.Select(p => (double)p.Y).ToArray(), degree); if (range_X == null) { range_X = new DRange(double.MaxValue, double.MinValue); Data.ForEach(p => { if (range_X.Min > p.X) range_X.Min = p.X; if (range_X.Max < p.X) range_X.Max = p.X; }); } IsFitted = true; } public double Evaluate(double x) { if (!IsFitted) return ErrNum; // 计算多项式在点 x 处的取值 double y = 0; for (int i = 0; i < coefficients.Count; i++) { y += coefficients[i] * Math.Pow(x, i); } return y; } double Solve(double y) { List points = FittedCurve.ToList(); PointF prevPoint = PointF.Empty; PointF nextPoint = PointF.Empty; foreach (var point in points) { if (point.Y == y) { return point.X; } else if (point.Y > y) { nextPoint = point; } else { prevPoint = point; break; } } if (prevPoint.IsEmpty) { return points[points.Count - 1].X; //throw new Exception("No valid interpolation range found."); } else if (nextPoint.IsEmpty) { return points[0].X; } double xDiff = nextPoint.X - prevPoint.X; double yDiff = nextPoint.Y - prevPoint.Y; double slope = yDiff / xDiff; double x = prevPoint.X + (y - prevPoint.Y) / slope; if (double.IsNaN(x)) return ErrNum; else return x; } public double Evaluate_Solve(double y) { if (!IsFitted) return ErrNum; if (degree == 2) // 多项式次数 { if (!is_Yvalue_validate(y)) return ErrNum; double a = coefficients[2]; // 二次项系数 double b = coefficients[1]; // 一次项系数 double c = coefficients[0] - y; // 常数项系数减去给定的 y 值 var roots = MathSolver.Solve(a, b, c); if (roots == null) return ErrNum; else return roots.Max(); } else if (degree == 3) { double a = coefficients[3]; // 3次项系数 double b = coefficients[2]; // 2次项系数 double c = coefficients[1]; // 1次项系数 double d = coefficients[0] - y;// 常数项系数减去给定的 y 值 var roots = MathSolver.Solve(a, b, c, d); if (roots == null) return ErrNum; else return roots.Max(); } else { return Solve(y); } } public double YMax { get { if (!IsFitted) return ErrNum; double a = coefficients[degree]; double b = coefficients[degree - 1]; double c = coefficients[0]; double delta = b * b - 4 * a * c; double minExtremePoint = -b / (2 * a);// 计算导函数的零点 double maxValue = 0; if (a < 0) maxValue = -delta / (4 * a) + c; else maxValue = a * minExtremePoint * minExtremePoint + b * minExtremePoint + c;// 计算最小值 return maxValue; } } public double YdataMax { get { double max = -99999; foreach (var p in Data) { if (max < p.Y) max = p.Y; } return max; } } public bool is_Yvalue_validate(double y) { if (!IsFitted) return false; double a = coefficients[degree]; if (a < 0) return y <= YMax; else return y >= YMax; } /// X显示的范围 public DRange range_X; /// Y显示的范围 public DRange range_Y; public bool HasData { get { return Data.Count >= 3; } } public bool IsFitted = false; public List FittedCurve { get { if (range_X == null) return null; List doubles = new List(); for (double x = range_X.Min; x <= range_X.Max; x += step) { double y = Evaluate(x); doubles.Add(new PointF((float)x, (float)y)); } return doubles; } } public List FittedCurvebyRange(DRange range) { List doubles = new List(); if (range == null) { range = new DRange(); range.Min = range_X.Min; range.Max = range_X.Max; } var step = (range.Max - range.Min) / stepNum; for (double x = range.Min; x <= range.Max; x += step) { double y = Evaluate(x); doubles.Add(new PointF((float)x, (float)y)); } return doubles; } } public class Default { static string _filePath = Path.Combine(Directory.GetCurrentDirectory(), @"default.ini"); public NodeViewModel junction; public ReservoirViewModel reservoir; public TankViewModel tank; public MeterViewModel meter; public NozzleViewModel nozzle; public LinkViewModel pipe; public ValveViewModel valve; public RepeaterViewModel repeater; public PumpViewModel pump; public static Default GetfaultINI() { StreamReader sr = new StreamReader(_filePath); string json = sr.ReadToEnd(); sr.Close(); return JsonConvert.DeserializeObject(json); } public void SaveFile() { StreamWriter sw = new StreamWriter(_filePath); sw.WriteLine(JsonConvert.SerializeObject(this)); sw.Close(); } public static Dictionary PreName = new Dictionary() { {MapObjectType.节点,"J" }, {MapObjectType.水库,"R" }, {MapObjectType.水池,"T" }, {MapObjectType.水表,"M" }, {MapObjectType.喷头,"N" }, {MapObjectType.管线,"P" }, {MapObjectType.阀门,"V" }, {MapObjectType.重复器,"Rp" }, {MapObjectType.水泵,"Pump" }, {MapObjectType.阀门点,"Vn" }, }; public static string GetPreString(IBaseViewModel obj) { return PreName[obj.Type]; } } public static class Global { public static List mapObjectRecords = new List(); public static int RecordIndex = 0; public static List curveStrings = new List() { "流量扬程曲线", "流量功率曲线", "流量效率曲线" }; public static void ClearFileReadOnly(string filePath) { if (File.Exists(filePath)) { // 获取当前文件属性 FileAttributes attributes = File.GetAttributes(filePath); // 如果文件被设置为只读,则移除只读属性 if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { attributes &= ~FileAttributes.ReadOnly; // 移除只读标志 // 设置新的文件属性 File.SetAttributes(filePath, attributes); } } } } public static class GlobalExtension { public static Type GetObjType(this MapObjectType type) { switch (type) { case MapObjectType.全部: return null; case MapObjectType.节点: return typeof(JunctionViewModel); case MapObjectType.水表: return typeof(MeterViewModel); case MapObjectType.水库: return typeof(ReservoirViewModel); case MapObjectType.水池: return typeof(TankViewModel); case MapObjectType.喷头: return typeof(NozzleViewModel); case MapObjectType.管线: return typeof(PipeViewModel); case MapObjectType.阀门: return typeof(ValveViewModel); case MapObjectType.重复器: return typeof(RepeaterViewModel); case MapObjectType.水泵: return typeof(PumpViewModel); case MapObjectType.阀门点: return typeof(ValveNodeViewModel); case MapObjectType.水泵点: return typeof(PumpNodeViewModel); default: return null; } } } public class MapObjectRecord { public IBaseViewModel mapObject { get; set; } public string ValueName { get; set; } public dynamic Value { get; set; } } public class MapDimensions { [Category("视角")] [DisplayName("中心")] [Browsable(true)] public PointF Center { get; set; } [Category("视角")] [DisplayName("缩放")] [Browsable(true)] public float zoom { get; set; } = 0.1f; [Category("视角")] [DisplayName("旋转角度")] [Browsable(true)] public double rotation { get; set; } = 0; private double _rotationF; [Category("视角")] [DisplayName("俯视角度")] [Browsable(true)] public double rotationF { get { if (Lock2DView) _rotationF = 90; return _rotationF; } set { _rotationF = value; if (Lock2DView) _rotationF = 90; } } [Category("视角")] [DisplayName("显示楼层")] [Browsable(true)] public int ShowFloor { get; set; } = int.MinValue; [Category("视角")] [DisplayName("显示背景")] [Browsable(true)] public bool isShowPic { get; set; } = true; public bool isAutoBackgroundImage = false; [Category("视角")] [DisplayName("显示最不利点")] [Browsable(true)] public bool isShowUnfavor { get; set; } = true; // //public int NodeColourIndex { get; set; } = 0; // //public int LinkColourIndex { get; set; } = 0; [Category("视角")] [DisplayName("锁定平面视角")] [Browsable(true)] public bool Lock2DView { get; set; } = false; /// 编辑模式true,浏览模式false;默认值:true;浏览模式下,不能编辑模型 public bool isEditMode { get; set; } = true; /// 正交模式 public bool IsOrtho { get; set; } = true; /// 显示的颜色分级 public ColourType ColourNode { get; set; } = ColourType.无; public ColourType ColourLink { get; set; } = ColourType.无; public MapDimensions Copy() { MapDimensions mv = new MapDimensions(); mv.Center = Center; mv.zoom = zoom; mv.rotation = rotation; mv.rotationF = rotationF; mv.ShowFloor = ShowFloor; return mv; } } public class UndoRedoCommand { private readonly Action _undoAction; private readonly Action _redoAction; private readonly T _oldValue; private readonly T _newValue; public UndoRedoCommand(T oldValue, T newValue, Action undoAction, Action redoAction) { _oldValue = oldValue; _newValue = newValue; _undoAction = undoAction; _redoAction = redoAction; } public void Undo() { _undoAction?.Invoke(_oldValue); } public void Redo() { _redoAction?.Invoke(_newValue); } } public static class MapObjectExtensions { private static readonly Stack> _undoStack = new Stack>(); private static readonly Stack> _redoStack = new Stack>(); public static void AddUndoRedoSupport(this List list, PropertyGrid propertyGrid) { propertyGrid.PropertyValueChanged += (sender, e) => { if (propertyGrid.SelectedObject is IBaseViewModel obj && obj != null) { var propertyDescriptor = TypeDescriptor.GetProperties(obj)[e.ChangedItem.PropertyDescriptor.Name]; var oldValue = e.OldValue;//propertyDescriptor.GetValue(obj); var newValue = e.ChangedItem.Value; var undoAction = new Action(v => propertyDescriptor.SetValue(obj, v)); var redoAction = new Action(v => propertyDescriptor.SetValue(obj, v)); var command = new UndoRedoCommand(oldValue, newValue, undoAction, redoAction); _undoStack.Push(command); _redoStack.Clear(); } }; } public static void AddCommand(UndoRedoCommand command) { _undoStack.Push(command); _redoStack.Clear(); } private static List getObj(object o) { var list = o as List; if (list == null) { if (o is List list_nodes) list = new List(list_nodes); if (o is List list_links) list = new List(list_links); } return list; } public static void AddCommand(object o, string PropertyDescriptorName, dynamic oldValue, dynamic newValue) { switch (PropertyDescriptorName) { case "Add": { var net = o as MapViewNetWork; var undoAction = new Action(v => net.Remove(newValue)); var redoAction = new Action(v => net.Add(newValue)); var command = new UndoRedoCommand(oldValue, newValue, undoAction, redoAction); AddCommand(command); } return; case "Remove": { var net = o as MapViewNetWork; var undoAction = new Action(v => net.Add(newValue)); var redoAction = new Action(v => net.Remove(newValue)); var command = new UndoRedoCommand(oldValue, newValue, undoAction, redoAction); AddCommand(command); } return; case "Map": { var mv = o as MapDimensions; var undoAction = new Action(v => { mv.Center = oldValue.Center; mv.zoom = oldValue.zoom; mv.rotation = oldValue.rotation; mv.rotationF = oldValue.rotationF; }); var redoAction = new Action(v => { mv.Center = newValue.Center; mv.zoom = newValue.zoom; mv.rotation = newValue.rotation; mv.rotationF = newValue.rotationF; }); //object oldValue=propertyDescriptor.GetValue(obj); var command = new UndoRedoCommand(oldValue, newValue, undoAction, redoAction); AddCommand(command); } return; } if (o is IBaseViewModel obj && obj != null) { var propertyDescriptor = TypeDescriptor.GetProperties(obj)[PropertyDescriptorName]; if (propertyDescriptor == null) return; var undoAction = new Action(v => propertyDescriptor.SetValue(obj, v)); var redoAction = new Action(v => propertyDescriptor.SetValue(obj, v)); var command = new UndoRedoCommand(oldValue, newValue, undoAction, redoAction); AddCommand(command); } else if (o is List || o is List) { var list = getObj(o); List> list_command = new List>(); PropertyDescriptor propertyDescriptor = null; for (int i = 0; i < list.Count; i++) { var item = list[i]; if (propertyDescriptor == null) propertyDescriptor = TypeDescriptor.GetProperties(item)[PropertyDescriptorName]; if (propertyDescriptor == null) continue; IBaseViewModel obj0 = (IBaseViewModel)item; var undoAction0 = new Action(v => propertyDescriptor.SetValue(obj0, v)); var redoAction0 = new Action(v => propertyDescriptor.SetValue(obj0, v)); var command0 = new UndoRedoCommand(oldValue[i], newValue[i], undoAction0, redoAction0); list_command.Add(command0); } var undoAction = new Action(v => { for (int i = 0; i < list_command.Count; i++) { list_command[i].Undo(); } }); var redoAction = new Action(v => { for (int i = 0; i < list_command.Count; i++) { list_command[i].Redo(); } }); var command = new UndoRedoCommand(null, null, undoAction, redoAction); AddCommand(command); } } public static void Undo() { if (_undoStack.Count > 0) { var command = _undoStack.Pop(); command.Undo(); _redoStack.Push(command); } } public static void Redo() { if (_redoStack.Count > 0) { var command = _redoStack.Pop(); command.Redo(); _undoStack.Push(command); } } } public class Colour { public string Name { get; set; } public ColourType Type { get; set; } public List Items { get; set; } public bool isNode { get { if (Type == ColourType.节点自由压力 || Type == ColourType.节点需水量) { return true; } else { return false; } } } public bool isChoosed { get; set; } = false; public float minNum = 0; public float maxNum = 50; public int ColourCount = 5; public Color color0 = Color.Red; public Color color1 = Color.Blue; public Colour(ColourType type = ColourType.节点自由压力, List value = null, string name = null) { Name = name; Type = type; Items = value; if (Items == null) Items = new List(); if (Name == null) Name = type.ToString(); } public override string ToString() { return Name; } public static List GetColourItems(float minValue, float maxValue, int ColourNum, Color color0, Color color1) { var colourItems = new List(); for (int i = 0; i < ColourNum; i++) { DRange currentRange = new DRange(minValue + i * (maxValue - minValue) / ColourNum, minValue + (i + 1) * (maxValue - minValue) / ColourNum); Color c; if (i == 0) { c = color0; } else if (i == ColourNum - 1) { c = color1; } else { c = Color.FromArgb(color0.R + (color1.R - color0.R) / (ColourNum - 1) * i, color0.G + (color1.G - color0.G) / (ColourNum - 1) * i, color0.B + (color1.B - color0.B) / (ColourNum - 1) * i); } ColourItem newFloor = new ColourItem(currentRange, c); colourItems.Add(newFloor); } return colourItems; } public static int NodeTypeCount = 3; } public class ColourItem { public DRange DRange { get; set; } = new DRange(); public Color value; public ColourItem(DRange dRange, Color value) { DRange = dRange; this.value = value; } } public enum ColourType { 无 = 0, 节点自由压力 = 1, 节点绝对压力 = 2, 节点需水量 = 3, 管线流量 = 4, 管线流速 = 5 } public class TempForEnum { public string Item1; public dynamic Item2; public TempForEnum(string key, dynamic value) { Item1 = key; Item2 = value; } } public class EquivalentTemplateModel { public string Name { get; set; } public long ID { get; set; } public List waterEquivalents { get; set; } } public class WaterEquivalentModel { /// 器具名称 public string WaterUtensilName { get; set; } /// 数量 public int Count { get; set; } /// 额定流量 public double RatedFlow { get; set; } /// 最小额定流量 public double MinRatedFlow { get; set; } } public class MapViewEnum { public enum MapObjectType { 全部, 节点, 水库, 水池, 水表, 喷头, 管线, 阀门, 重复器, 水泵, 阀门点, 水泵点, } public enum MouseState { 无, 新增节点, 新建水库, 新建水池, 新建水表, 新增喷头, 新增管线, 新增立管, 新建阀门, 新建重复器, 新建水泵, 设置底图范围, } public enum FactoryType { 水厂, 泵站 } public enum TemplateType { 全部, 小区模板, 单元模板, 单元分区模板, 楼层模板, 其他 } } public class AreaViewModel : NodeViewModel, IBaseViewModel { public List InnerNodes = new List(); public Color color { get; set; } } public class Factory { public string Name { get; set; } public MapViewEnum.FactoryType Type { get; set; } public List Pumps { get; set; } public void CurveFit() { foreach (var p in Pumps) { p.CurveFit(); } } } public class JunctionViewModel : NodeViewModel { public override string ToString() { var pTemp = PatternID; if (string.IsNullOrEmpty(pTemp) || pTemp == ";") pTemp = ""; return $"{ID}\t{Elev}\t{Demand}\t{pTemp}\t;\t"; } } public class MeterViewModel : NodeViewModel { public string DlTemplateID { get; set; } public override string ToString() { if (string.IsNullOrEmpty(PatternID)) PatternID = ""; return $"{ID}\t{Elev}\t{Demand}\t{PatternID}\t;\t"; } } public class NozzleViewModel : NodeViewModel { [Description("房间")] [DisplayName("房间")] public string Room { get; set; } [Category("计算参数")] [Description("流量系数")] [DisplayName("流量系数K")] public float FlowCoefficient { get; set; } public override string ToString() { if (string.IsNullOrEmpty(PatternID)) PatternID = ""; return $"{ID}\t{Elev}\t{Demand}\t{PatternID}\t;\t"; } } public class PipeViewModel : LinkViewModel { } public class PointF3D { public float X { get; set; } public float Y { get; set; } public float Z { get; set; } public PointF3D(float x, float y, float z) { X = x; Y = y; Z = z; } //定义减法运算符 public static PointF3D operator -(PointF3D p1, PointF3D p2) { return new PointF3D(p1.X - p2.X, p1.Y - p2.Y, p1.Z - p2.Z); } //定义加法运算符 public static PointF3D operator +(PointF3D p1, PointF3D p2) { return new PointF3D(p1.X + p2.X, p1.Y + p2.Y, p1.Z + p2.Z); } //定义乘法运算符 public static PointF3D operator *(PointF3D p1, float f) { return new PointF3D(p1.X * f, p1.Y * f, p1.Z * f); } //定义点乘运算符 public static float operator *(PointF3D p1, PointF3D p2) { return p1.X * p2.X + p1.Y * p2.Y + p1.Z * p2.Z; } //定义叉乘运算符 public static PointF3D operator ^(PointF3D p1, PointF3D p2) { return new PointF3D(p1.Y * p2.Z - p1.Z * p2.Y, p1.Z * p2.X - p1.X * p2.Z, p1.X * p2.Y - p1.Y * p2.X); } } public class Cube { public Dictionary> FacesVertices { get; private set; } public List Vertices { get; private set; } public Cube() { InitializeVertices(); InitializeFaces(); } private void InitializeVertices() { Vertices = new List { new PointF3D(200, 200, 200), // Vertex 0 new PointF3D(200, 200, -200), // Vertex 1 new PointF3D(200, -200, 200), // Vertex 2 new PointF3D(200, -200, -200), // Vertex 3 new PointF3D(-200, 200, 200), // Vertex 4 new PointF3D(-200, 200, -200), // Vertex 5 new PointF3D(-200, -200, 200), // Vertex 6 new PointF3D(-200, -200, -200) // Vertex 7 }; } private void InitializeFaces() { FacesVertices = new Dictionary> { { 1, new List { Vertices[0], Vertices[1], Vertices[3], Vertices[2] } }, // Face 1 { 2, new List { Vertices[4], Vertices[5], Vertices[7], Vertices[6] } }, // Face 2 { 3, new List { Vertices[0], Vertices[1], Vertices[5], Vertices[4] } }, // Face 3 { 4, new List { Vertices[2], Vertices[3], Vertices[7], Vertices[6] } }, // Face 4 { 5, new List { Vertices[0], Vertices[2], Vertices[6], Vertices[4] } }, // Face 5 { 6, new List { Vertices[1], Vertices[3], Vertices[7], Vertices[5] } }// Face 6 }; } } public class PumpNodeViewModel : NodeViewModel { public PumpNodeViewModel() { Datasets = new Dictionary() { {"流量扬程曲线",new Dataset("流量扬程曲线",new PumpViewModel())}, {"流量功率曲线",new Dataset("流量功率曲线",new PumpViewModel()) }, {"流量效率曲线",new Dataset("流量效率曲线",new PumpViewModel()) } }; } public string HeadCurve { get; set; } public List Parameters { get; set; } public string Node1 { get; set; } public string Node2 { get; set; } public Dictionary Datasets { get; set; } public double 额定转速 { get; set; } = 1500; public double 额定流量 { get; set; } = 0; public double 额定扬程 { get; set; } = 0; public double 额定功率 { get; set; } = 75; public double 当前转速 { get; set; } = 1500; public double 转速比 { get; set; } = 1; public Dataset 流量扬程曲线 { get { return Datasets["流量扬程曲线"]; } } public Dataset 流量功率曲线 { get { return Datasets["流量功率曲线"]; } } public Dataset 流量效率曲线 { get { return Datasets["流量效率曲线"]; } } } public class PumpViewModel : LinkViewModel { public static List CurveStrings = new List { "流量扬程曲线", "流量功率曲线", "流量效率曲线" }; public new string Name { get { return base.Name; } set { base.Name = value; } } [DisplayName("水泵类型")] public new PumpType Type { get; set; } public dict Datasets { get; set; } = new dict(); [Category("计算参数")] public double 额定转速 { get; set; } = 1500; [Category("计算参数")] public double 额定流量 { get; set; } = 200; [Category("计算参数")] public double 额定扬程 { get; set; } = 50; [Category("计算参数")] public double 额定功率 { get; set; } = 75; public double 转速比 { get; set; } = 1; [DisplayName("当前转速")] [Category("计算参数")] public double 当前转速 { get; set; } = 1500; public Dataset 流量扬程曲线 { get { if (!Datasets.ContainsKey("流量扬程曲线")) Datasets.Add("流量扬程曲线", new Dataset("流量扬程曲线", null)); return Datasets["流量扬程曲线"]; } } public Dataset 流量功率曲线 { get { if (!Datasets.ContainsKey("流量功率曲线")) Datasets.Add("流量功率曲线", new Dataset("流量功率曲线", null)); return Datasets["流量功率曲线"]; } } public Dataset 流量效率曲线 { get { if (!Datasets.ContainsKey("流量效率曲线")) Datasets.Add("流量效率曲线", new Dataset("流量效率曲线", null)); return Datasets["流量效率曲线"]; } } public string factoryName { set; get; } public Factory factory { get; set; } = null; public PumpViewModel Copy() { PumpViewModel p = new PumpViewModel(); p.Name = Name; p.额定流量 = 额定流量; p.额定扬程 = 额定扬程; p.额定功率 = 额定功率; p.额定转速 = 额定转速; p.当前转速 = 当前转速; p.Type = Type; p.factory = factory; foreach (var str in CurveStrings) { if (!p.Datasets.ContainsKey(str)) { p.Datasets.Add(str, new Dataset(str, p)); } } foreach (var pair in Datasets) { List list = new List(); pair.Value._data.ForEach(m => list.Add(m)); p.Datasets[pair.Key].Data = list; DRange rangeDefault = new DRange(double.MaxValue, double.MinValue); p.Datasets[pair.Key].range_X = DRange.Union(rangeDefault, pair.Value.range_X); p.Datasets[pair.Key].range_Y = DRange.Union(rangeDefault, pair.Value.range_Y); } p.CurveFit(); return p; } public void CurveFit() { foreach (var data in Datasets) { data.Value.Data.Sort((a, b) => a.X > b.X ? 1 : (a.X == b.X ? 0 : -1)); if (data.Value.HasData) data.Value.CurveFit(); } string basetype = "流量扬程曲线"; string type = ""; type = "流量效率曲线"; var type1 = "流量功率曲线"; if (!Datasets.ContainsKey(type)) Datasets.Add(type, new Dataset(type, null)); if (!Datasets.ContainsKey(type1)) Datasets.Add(type1, new Dataset(type1, null)); if (Datasets[type].IsFitted && !Datasets[type1].IsFitted) { List points = new List(); List points1 = new List(); foreach (var yc in Datasets[basetype].Data) { float x = yc.X; float y_扬程 = yc.Y; float y_效率 = (float)Datasets[type].Evaluate(x); float y_功率 = (float)x * y_扬程 / y_效率 / 3.6f; points.Add(new PointF(x, y_效率)); points1.Add(new PointF(x, y_功率)); } Datasets[type].Data = points; Datasets[type1].Data = points1; Datasets[type].CurveFit(); Datasets[type1].CurveFit(); } if (!Datasets[type].IsFitted && Datasets[type1].IsFitted) { List points = new List(); List points1 = new List(); foreach (var yc in Datasets[basetype].Data) { float x = yc.X; float y_扬程 = yc.Y; float y_功率 = (float)Datasets[type1].Evaluate(x); float y_效率 = (float)x * y_扬程 / y_功率 / 3.6f; points.Add(new PointF(x, y_效率)); points1.Add(new PointF(x, y_功率)); } Datasets[type].Data = points; Datasets[type1].Data = points1; Datasets[type].CurveFit(); Datasets[type1].CurveFit(); } } public void ShowInGrid(DataGridView dataGridView) { dataGridView.Rows.Clear(); // if () for (int i = 0; i < 流量扬程曲线.Data.Count; i++) { PointF p = 流量扬程曲线.Data[i]; PointF p_temp; double y1 = 0, y2 = 0; if (流量功率曲线.IsFitted) { if ((p_temp = 流量功率曲线.Data.Find(p0 => p0.X == p.X)) == default(PointF)) y1 = 流量功率曲线.Evaluate(p.X); else y1 = p_temp.Y; } if (流量效率曲线.IsFitted) { if ((p_temp = 流量效率曲线.Data.Find(p0 => p0.X == p.X)) == default(PointF)) y2 = 流量效率曲线.Evaluate(p.X); else y2 = p_temp.Y; } dataGridView.Rows.Add(Math.Round(p.X, 1), Math.Round(p.Y, 2), Math.Round(y1, 2), Math.Round(y2, 2)); } } [Category("计算参数")] [DisplayName("流量扬程曲线")] public List HeadCurvePoints { get { this.Datasets.TryGetValue("流量扬程曲线", out Dataset dataset); if (dataset != null) { return dataset._data; } return null; } set { this.Datasets.TryGetValue("流量扬程曲线", out Dataset dataset); if (dataset == null) { dataset = new Dataset("流量扬程曲线", this); } dataset._data = value; } } [Category("计算参数")] [DisplayName("流量效率曲线")] public List EfficCurvePoints { get { this.Datasets.TryGetValue("流量效率曲线", out Dataset dataset); if (dataset != null) { return dataset._data; } return null; } set { this.Datasets.TryGetValue("流量效率曲线", out Dataset dataset); if (dataset == null) { dataset = new Dataset("流量效率曲线", this); } dataset._data = value; } } public string HeadCurve { get; set; } = "PumpDefault"; public List Parameters { get; set; } //实际需水量 [DisplayName("扬程")] [Browsable(true)] public new float EN_HEADLOSS { get { return -base.EN_HEADLOSS; } } public new float EN_VELOCITY { get { return base.EN_VELOCITY; } } public override string ToString() { string para = Parameters == null ? null : string.Join("\t", Parameters); return $"{ID}\t{Node1}\t{Node2}\tHead\t{HeadCurve}\tSPEED\t{转速比}\t{para}\t;\t"; } } public class RepeaterViewModel : LinkViewModel { [DisplayName("对象前缀名称")] [Browsable(true)] /// 模板ID public string NetworkPreName { get; set; } [DisplayName("显示名称")] [Browsable(true)] /// 模板ID public string NetworkShowName { get; set; } [DisplayName("前缀最小序号")] [Browsable(true)] /// 模板ID public int NetworkPreStartNum { get; set; } = 1; [DisplayName("前缀正序")] [Browsable(true)] /// 模板ID public bool NetworkIsAscNum { get; set; } = true; [Category("计算参数")] [DisplayName("模板ID")] /// 模板ID public string TemplateID { get; set; } [Category("计算参数")] [DisplayName("模板名称")] [Browsable(true)] public string TempName => TemplateList.GetTemplate(TemplateID)?.Name; public Template template = null; [NonSerialized] public MapViewNetWork netList = null; public NodeViewModel StartNode_inner; public NodeViewModel EndNode_inner; public bool isLoadded = false; [Category("计算参数")] [DisplayName("重复次数")] [Browsable(true)] /// 重复次数 public int RepeatTimes { get; set; } [Category("计算参数")] [DisplayName("海森威廉系数")] public new float Roughness { get; set; } [Category("计算参数")] [DisplayName("局部阻力系数")] public override float MinorLoss { get; set; } [DisplayName("长度(m)")] [Browsable(true)] public new float Length { get; set; } [DisplayName("口径(mm)")] public new float Diameter { get; set; } [Category("计算参数")] [DisplayName("显示状态")] [Browsable(true)] public new RepeatStatus Status { get; set; } public bool Load(int MaxLevel, dict param, Dictionary viewModel, bool viewMode = true) { if (template == null) { template = TemplateList.GetTemplate(TemplateID); if (template == null) { return false; } template.loadInpFile(); template.network.MapObjects.ForEach(o => { if (o.Level > MaxLevel) o.Visible = false; else o.Visible = true; }); MapViewNetWork net = template.network; net.StartPoint = net.GetNode(template.Node1)[0]; net.EndPoint = net.GetNode(template.Node2)[0]; } if (!viewMode) { Status = RepeatStatus.收起; } else if (viewModel != null) { if (viewModel[template.Type]) Status = RepeatStatus.显示; else Status = RepeatStatus.收起; } else { Status = RepeatStatus.显示; } if (param.Contains("层数") && param["层数"] > 0 && template.Type == TemplateType.楼层模板) { RepeatTimes = (int)param["层数"]; } if (Status == RepeatStatus.收起) { return false; } PointF3D basepoint = StartNode.Position3D; netList = new MapViewNetWork(); for (int i = 0; i < RepeatTimes; i++) { MapViewNetWork net = template.network.CreateNew(basepoint); int index = GetIndex(i); net.Name = NetworkPreName + (index == 0 ? "" : index.ToString("00")); net.StartPoint = net.GetNode(template.Node1)[0]; net.EndPoint = net.GetNode(template.Node2)[0]; if (template.Type == TemplateType.楼层模板) ChangeNetbyParam(net, param); if (i == 0) StartNode_inner = net.StartPoint; EndNode_inner = net.EndPoint; net.LoadRepeaters(MaxLevel, param, viewModel); net.Rename(); netList.AddJoinNet(net); basepoint = netList.EndPoint.Position3D; } return true; } void ChangeNetbyParam(MapViewNetWork net, dict param) { if (param.Contains("层高") && param["层高"] > 0 && net.StartPoint != null && net.EndPoint != null) { var currentHeight = Math.Abs(net.StartPoint.Elev - net.EndPoint.Elev); var k = (float)param["层高"] / currentHeight; net.Nodes.ForEach(n => n.Elev = (n.Elev - net.StartPoint.Elev) * k + net.StartPoint.Elev); } if (param.Contains("系统最大流量") && param["系统最大流量"] > 0 && net.StartPoint != null && net.EndPoint != null) { Dictionary Distance = new Dictionary(); CalcDistance(net, net.StartPoint, Distance); float sumDistance = 0; net.meters.ForEach(m => sumDistance += Distance[m]); float avgDistance = sumDistance / net.meters.Count; var k = (float)param["系统最大流量"] / avgDistance; net.Nodes.ForEach(n => { n.X = (n.X - net.StartPoint.X) * k + net.StartPoint.X; n.Y = (n.Y - net.StartPoint.Y) * k + net.StartPoint.Y; }); } if (param.Contains("户数") && template.Type == TemplateType.楼层模板) { var MaxLevel = (int)param["户数"]; net.MapObjects.ForEach(o => { if (o.Level > MaxLevel) o.Visible = false; else o.Visible = true; }); } } public static void CalcDistance(MapViewNetWork net, NodeViewModel startNode, Dictionary Distance) { // 定义 visited 字典记录已访问过的节点和待访问的节点队列 Queue queue = new Queue(); // 标记起始节点为已访问,并加入队列 Distance[startNode] = 0; queue.Enqueue(startNode); // 不断从队列中取出节点进行访问,直到队列为空 while (queue.Count > 0) { // 取出队首节点并输出 NodeViewModel node = queue.Dequeue(); //Console.WriteLine(node.Name); // 遍历当前节点的所有未访问邻居节点,并标记为已访问 foreach (LinkViewModel link in net.Links) { if (link.StartNode == node) { var node1 = link.EndNode; var dis = Distance[node] + (float)Math.Sqrt(Math.Pow(node.X - node1.X, 2) + Math.Pow(node.Y - node1.Y, 2)); if (!Distance.ContainsKey(node1) || Distance[node1] > dis) Distance[link.EndNode] = dis; queue.Enqueue(link.EndNode); } else if (link.EndNode == node && !Distance.ContainsKey(link.StartNode)) { var node1 = link.StartNode; var dis = Distance[node] + (float)Math.Sqrt(Math.Pow(node.X - node1.X, 2) + Math.Pow(node.Y - node1.Y, 2)); if (!Distance.ContainsKey(node1) || Distance[node1] > dis) Distance[link.StartNode] = dis; queue.Enqueue(link.StartNode); } } } } public int GetIndex(int i) { int index = 0; if (NetworkIsAscNum) { index = NetworkPreStartNum + i; } else { index = RepeatTimes - 1 - i + NetworkPreStartNum; } return index; } public enum RepeatStatus { 收起, 显示 } } public class ReservoirViewModel : NodeViewModel { [Category("计算参数")] [Description("需水量")] [DisplayName("需水量(m³/h)")] public new float Demand { get; set; } [Category("计算参数")] [Description("总水头")] [DisplayName("绝对水压(m)")] public float Head { get; set; } //public string Pattern { get; set; } public override string ToString() { return $"{ID}\t{Head}\t{PatternID}\t;\t"; } } public class TankViewModel : NodeViewModel { [Category("计算参数")] [DisplayName("初始水位(m)")] public float InitLevel { get; set; } = 5; [Category("计算参数")] [DisplayName("最低水位(m)")] public float MinLevel { get; set; } = 0; [Category("计算参数")] [DisplayName("最高水位(m)")] public float MaxLevel { get; set; } = 10; [Category("计算参数")] [DisplayName("直径(mm)")] public float Diameter { get; set; } = 10; [Category("计算参数")] [DisplayName("池底面积")] public double Area { get { return Math.PI * Math.Pow(Diameter, 2) / 4; } set { Diameter = (float)Math.Pow(value / Math.PI, 0.5) * 2; } } [Category("计算参数")] [DisplayName("最小容积")] public float MinVol { get; set; } = 0; [Category("计算参数")] [DisplayName("容积曲线")] public string VolCurve { get; set; } = ""; [Category("计算参数")] [DisplayName("是否允许溢流")] public string Overflow { get; set; } = ""; public TankViewModel() { } public TankViewModel(string id, string elevation, string initlevel, string minlevel, string maxlevel, string diameter, string minvol, string volcurve, string overflow) { ID = id; Elev = float.Parse(elevation); float d = 0; float.TryParse(initlevel, out d); InitLevel = d; float.TryParse(minlevel, out d); MinLevel = d; float.TryParse(maxlevel, out d); MaxLevel = d; float.TryParse(diameter, out d); Diameter = d; float.TryParse(minvol, out d); MinVol = d; VolCurve = ""; //float.TryParse(overflow, out d ); Overflow = ""; } public override string ToString() { VolCurve = ""; Overflow = ""; return $"{ID}\t{Elev}\t{InitLevel}\t{MinLevel}\t{MaxLevel}\t{Diameter}\t{MinVol}\t{VolCurve}\t{Overflow}\t;\t"; } } public class ValveNodeViewModel : NodeViewModel { public string Node1 { get; set; } public string Node2 { get; set; } [DisplayName("长度(m)")] [Browsable(true)] public float Length { get; set; } [DisplayName("口径(mm)")] [Browsable(true)] public float Diameter { get; set; } [Category("计算参数")] [DisplayName("海森威廉系数")] [Browsable(true)] public float Roughness { get; set; } = 110; [Category("计算参数")] [DisplayName("局部阻力系数")] [Browsable(true)] public float MinorLoss { get; set; } = 0; [Category("计算参数")] [DisplayName("初始状态")] [Browsable(true)] public new StatusType Status { get; set; } [Browsable(true)] public new string Type { get; set; } = "GPV"; [DisplayName("曲线")] [Browsable(true)] public string Setting { get; set; } = "GPVDefault"; } public class ValveViewModel : LinkViewModel { [DisplayName("长度(m)")] [Browsable(true)] public new float Length { get; set; } [DisplayName("口径(mm)")] [Browsable(true)] public new float Diameter { get; set; } [Category("计算参数")] [DisplayName("海森威廉系数")] [Browsable(true)] public new float Roughness { get; set; } = 110; [Category("计算参数")] [DisplayName("局部阻力系数")] [Browsable(true)] public new float MinorLoss { get; set; } = 0; //[Category("计算参数")] //[DisplayName("初始状态")] //[Browsable(true)] //public string Status { get; set; } = ""; [Browsable(true)] public new string Type { get; set; } = "GPV"; [DisplayName("曲线")] [Browsable(true)] public string Setting { get; set; } = "GPVDefault"; // 重写ToString()方法以便将阀门属性转换为字符串 public override string ToString() { return $"{ID}\t{Node1}\t{Node2}\t{Diameter:F4}\t{Type}\t{Setting}\t{MinorLoss:F4}\t;\t"; } } public class TRegion { public string Name { get; set; } = "新分区"; public List Floors { get; set; } = new List(); public bool isDirectionUp { get; set; } = true; public string JoinNode { get; set; } = null; public override string ToString() { return Name; } } public class Floor { public int FloorIndex = 1; public string BackgroundImg = null; public float Elev = 0; public MapDimensions MapView { get; set; } = null; public string Name => $"{FloorIndex}楼"; public Floor() { } public string TemplateID { get; set; } = null; public Template template { get { return TemplateList.GetTemplate(TemplateID); } } public Floor(int floorIndex, string tempID, float floorElevation, MapDimensions otherInfo) { FloorIndex = floorIndex; TemplateID = tempID; Elev = floorElevation; MapView = otherInfo; } } public class Template { private string _ID; [Description("对象的ID唯一标识")] [DisplayName("模板ID")] [Browsable(true)] public string ID { get { if (_ID == null || _ID == "") _ID = Guid.NewGuid().ToString(); return _ID; } set { _ID = value; } } [DisplayName("名称")] public string Name { get; set; } public MapOption mapOption { get; set; } = new MapOption(); private string _filePath = null; [Category("计算参数")] [DisplayName("路径INP")] public string filePath { get { return _filePath; } set { var filePath = value; var CurDir = Directory.GetCurrentDirectory(); if (filePath != null && filePath.IndexOf(CurDir) >= 0) { filePath = filePath.Replace(CurDir, ""); if (filePath[0] == '\\') filePath = filePath.Substring(1); } _filePath = filePath; } } public PointF3D OffSet { get; set; } = new PointF3D(0, 0, 0); private string _BackGroundImg_FullPath; public string BackGroundImg_FullPath { get { if (string.IsNullOrEmpty(_BackGroundImg_FullPath)) { FileInfo fi = new FileInfo(FullPath); return fi.FullName.Substring(0, fi.FullName.Length - fi.Extension.Length) + ".png"; } else return _BackGroundImg_FullPath; } set { _BackGroundImg_FullPath = value; } } public float BackGroundElev = 0; /// 底图X public float BackGroundImgX = 0; /// 底图Y public float BackGroundImgY = 0; /// 底图高度 public float BackGroundImgHeight = 0; /// 底图宽度 public float BackGroundImgWidth = 0; /// 底图旋转角度 public float BackGroundImgRotaAngle = 0; public PointF BackGroundPoint1 = new PointF(); public PointF BackGroundPoint2 = new PointF(); public string FullPath { get { if (filePath != null) filePath = filePath.TrimStart('\\'); return Path.Combine(Directory.GetCurrentDirectory(), (filePath == null ? "" : filePath)); } } public string ImportExcelPath { get; set; } public int ImportExcelIndex { get; set; } [Category("计算参数")] [DisplayName("最高级数")] public int MaxLevel { get; set; } = 99; [Browsable(true)] public TemplateType Type { get; set; } public Template() { ID = new Guid().ToString(); Name = "临时"; filePath = null; } public Template(string ID, string name, string address, TemplateType type) { if (ID == null) this.ID = new Guid().ToString(); Name = name; filePath = address; Type = type; } [Description("对象的ID唯一标识")] [NonSerialized] public MapViewNetWork network = null; [Category("楼层")] [DisplayName("楼层")] public List Regions { get; set; } = null; [DisplayName("标高")] public float Elev { get { return 0; } } public float Diameter { get { return 0; } } public float Level { get { return 0; } } [DisplayName("开始节点")] public string Node1 { get; set; } [DisplayName("结束节点")] public string Node2 { get; set; } public string X { get; set; } public string Y { get; set; } public string Visible { get; set; } [Category("默认视角")] [DisplayName("视角")] public MapDimensions view { get; set; } = new MapDimensions(); [Category("默认视角")] [DisplayName("中心X")] [Browsable(true)] public float CenterX { get { if (view != null) return view.Center.X; else return 0; } set { if (view == null) view = new MapDimensions(); view.Center = new PointF(value, view.Center.Y); } } [Category("默认视角")] [DisplayName("中心Y")] [Browsable(true)] public float CenterY { get { if (view != null) return view.Center.Y; else return 0; } set { if (view == null) view = new MapDimensions(); view.Center = new PointF(view.Center.X, value); } } [Category("默认视角")] [DisplayName("缩放")] [Browsable(true)] public float zoom { get { if (view != null) return view.zoom; else return 1f; } set { if (view == null) view = new MapDimensions(); view.zoom = value; } } [Category("默认视角")] [DisplayName("旋转角度")] [Browsable(true)] public double rotation { get { if (view != null) return view.rotation; else return 0; } set { if (view == null) view = new MapDimensions(); view.rotation = value; } } [Category("默认视角")] [DisplayName("俯视角度")] [Browsable(true)] public double rotationF { get { if (view != null) return view.rotationF; else return 90; } set { if (view == null) view = new MapDimensions(); view.rotationF = value; } } public bool loadInpFile() { network = new MapViewNetWork(); var result = network.BuildFromInp(FullPath); if (result) { network.MapObjects.ForEach(o => { if (o.Level > MaxLevel) o.Visible = false; else o.Visible = true; }); return true; } else return false; } [DisplayName("颜色分级方案")] public List Colours { get; set; } = new List(); } public class TemplateList { public List