| | |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | using System.Windows.Forms.DataVisualization.Charting; |
| | | using static Hydro.Core.ObjectEnum; |
| | | //using static Hydro.Core.ObjectEnum; |
| | | using static Hydro.MapView.MapViewEnum; |
| | | using static System.Net.Mime.MediaTypeNames; |
| | | using static System.Windows.Forms.AxHost; |
| | |
| | | |
| | | |
| | | //} |
| | | |
| | | public MapViewer(bool showToolBar = false) |
| | | { |
| | | |
| | |
| | | |
| | | //if (!showToolBar) this.panel1.Visible = false; |
| | | } |
| | | public MapViewer() |
| | | public MapViewer() |
| | | { |
| | | |
| | | this.showToolBar = false; |
| | |
| | | |
| | | MapCenter = PointF.Empty; |
| | | zoom = 1.0f; |
| | | DoubleBuffered = true; |
| | | |
| | | SetStyle(ControlStyles.SupportsTransparentBackColor, true); |
| | | BackColor = Color.Transparent; |
| | | |
| | | } |
| | | public void SetEditMode(bool isEditMode) |
| | | { |
| | | _IsEditMode = isEditMode; |
| | | } |
| | | private void MapViewer_Load(object sender, EventArgs e) |
| | | { |
| | |
| | | |
| | | cb_Link_Colour.SelectedIndex = 0; |
| | | |
| | | |
| | | <<<<<<< HEAD |
| | | map.Init(TC,new DrawDelegate[] { Draw, Draw, DrawBackGroud, DrawH },new MouseDelegate[] { mapMouseDown, mapMouseMove, mapMouseUp, mapMouseWheel }); |
| | | ======= |
| | | map.Init(TC, new DrawDelegate[] { Draw, Draw, DrawH }, new MouseDelegate[] { mapMouseDown, mapMouseMove, mapMouseUp, mapMouseWheel }); |
| | | |
| | | >>>>>>> 0f2ff322746347b91941d936ee27067295e57c76 |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | #endregion |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | SuspendLayout(); |
| | | if (_ViewModel == null) |
| | | { |
| | | if (!_IsEditMode) |
| | |
| | | |
| | | SetStartEndPoint(_Template.Node1, _Template.Node2); |
| | | |
| | | |
| | | ResumeLayout(false); |
| | | return true; |
| | | } |
| | | |
| | |
| | | zoom = 1.0f; |
| | | Rotation = 0; |
| | | RotationF = 90; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | public void SetData(Template template, dict<string, dynamic> param = null, Dictionary<TemplateType, bool> viewMode = null) |
| | | { |
| | |
| | | // { |
| | | // this.mapOption= f.MapView.Copy(); |
| | | // } |
| | | // this.Invalidate(); |
| | | // this.SetInvalidated(); |
| | | // }; |
| | | // ToolStripMenuItem_Floor.DropDownItems.Add(btn); |
| | | |
| | |
| | | //Rotation = _Template.view.rotation; |
| | | //RotationF = _Template.view.rotationF; |
| | | this.mapOption = _Template.view.Copy(); |
| | | SetInvalidated(); |
| | | SetMapInvalidate(); |
| | | } |
| | | } |
| | | |
| | | 刷新楼层ToolStripMenuItem_Click(1, new EventArgs()); |
| | | //Invalidate(); |
| | | 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")})"; |
| | | //SetInvalidated(); |
| | | } |
| | | |
| | | private void InitCenter() |
| | |
| | | |
| | | float x_span = x1 - x0, y_span = y1 - y0; |
| | | |
| | | zoom = Math.Min(Width / x_span, Height / y_span); |
| | | zoom = Math.Min(this.map.Width / x_span, this.map.Height / y_span); |
| | | zoom = Math.Max(zoom, MinZoom); |
| | | zoom = Math.Min(zoom, MaxZoom); |
| | | |
| | |
| | | MapCenter = p; |
| | | } |
| | | |
| | | public void SetInvalidated() |
| | | public void SetMapInvalidate() |
| | | { |
| | | |
| | | Invalidate(); |
| | | _needPaintAll = true; |
| | | PMin_Show = ScreenToMap(new PointF(0, this.map.Height)); |
| | | PMax_Show = ScreenToMap(new PointF(this.map.Width, 0)); |
| | | _timerDraw = true; |
| | | |
| | | |
| | | } |
| | |
| | | { |
| | | _StartPoint = node1; |
| | | _EndPoint = node2; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | public void Set3DView(bool is3Dview, double 俯视角度) |
| | | |
| | | { |
| | | this.RotationF = 俯视角度; |
| | | this.is3Dview = is3Dview; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | |
| | |
| | | public void SetRotation(double d) |
| | | { |
| | | this.Rotation = d; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #region 基础坐标转换方法 |
| | | /// <summary> |
| | | /// 将屏幕坐标转换为世界坐标。输入屏幕坐标 (x,y),返回世界坐标 (wx, wy)。 |
| | | /// </summary> |
| | | /// <param name="screenPos"></param> |
| | | /// <returns></returns> |
| | | private PointF ScreenToVMap(PointF screenPos, float z = 0) |
| | | { |
| | | |
| | | var centerX = Width / 2; |
| | | var centerY = Height / 2; |
| | | var worldX = (screenPos.X - centerX - Z(z).X) / Zoom.X + MapCenter.X; |
| | | var worldY = (screenPos.Y - centerY) / Zoom.Y + 0; |
| | | //if (is3Dview) worldY = -(screenPos.Y - centerY + 2 * z) / (0.5f* zoom) + center.Y; |
| | | return new PointF(worldX, worldY); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 将屏幕坐标转换为世界坐标。输入屏幕坐标 (x,y),返回世界坐标 (wx, wy)。 |
| | | /// </summary> |
| | | /// <param name="screenPos"></param> |
| | | /// <returns></returns> |
| | | private PointF ScreenToMap(PointF screenPos, float z = 0) |
| | | { |
| | | |
| | | var centerX = Width / 2; |
| | | var centerY = 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; |
| | | //if (is3Dview) worldY = -(screenPos.Y - centerY + 2 * z) / (0.5f* zoom) + center.Y; |
| | | return new PointF(worldX, worldY); |
| | | } |
| | | |
| | | private PointF MapToScreen(PointF mapPos, float z = 0) |
| | | { |
| | | |
| | | var centerX = Width / 2; |
| | | var centerY = 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 center = MapCenter; |
| | | 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 center = MapCenter; |
| | | 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 center = MapCenter; |
| | | 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 center = MapCenter; |
| | | 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); |
| | | } |
| | | /// <summary> |
| | | /// 获取地图投影坐标 |
| | | /// </summary> |
| | | /// <param name="point"></param> |
| | | /// <param name="z"></param> |
| | | /// <returns></returns> |
| | | 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); |
| | | |
| | | var pointT = Get俯视角旋转Point(pointR, z + offset.Z); |
| | | |
| | | //var n=new PointF((float)pointR.X - Z(z).X, (float)(pointR.Y - Z(z).Y)); |
| | | return pointT; |
| | | } |
| | | 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 List<PointF> WorldPointToMapPoint(LinkViewModel pipe, PointF3D offset = null) |
| | | { |
| | | List<PointF> list = new List<PointF>(); |
| | | |
| | | PointF p; |
| | | p = WorldPointToMapPoint(pipe.StartNode, offset); |
| | | list.Add(p); |
| | | p = WorldPointToMapPoint(pipe.EndNode, offset); |
| | | list.Add(p); |
| | | return list; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取地图投影坐标 |
| | | /// </summary> |
| | | /// <param name="point"></param> |
| | | /// <param name="z"></param> |
| | | /// <returns></returns> |
| | | private PointF MapPointToWorldPoint(PointF point, float z = 0) |
| | | { |
| | | var pointT = Get俯视角还原Point(point, z); |
| | | pointT = Get平面还原Point(pointT); |
| | | |
| | | //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 判断可见性 |
| | | 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; |
| | | |
| | | /// <summary> |
| | | /// 判断是否在屏幕坐标内 |
| | | /// </summary> |
| | | /// <param name="screenPos"></param> |
| | | /// <returns></returns> |
| | | 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; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 判断是否在屏幕坐标内 |
| | | /// </summary> |
| | | /// <param name="screenPos"></param> |
| | | /// <returns></returns> |
| | | public bool isVisible(List<PointF> 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 |
| | | |
| | | |
| | | |
| | | #region 重绘函数 |
| | | |
| | | bool _needPaintAll = false; |
| | | protected override void OnPaint(PaintEventArgs e) |
| | | bool _needPaintAll |
| | | { |
| | | base.OnPaint(e); |
| | | |
| | | if (float.IsInfinity(zoom)) return; |
| | | |
| | | label_center.Text = $"center:({MapCenter.X.ToString("0.00")} ,{MapCenter.Y.ToString("0.00")})"; |
| | | label_zoom.Text = $"Zoom:{zoom.ToString("0.000")}"; |
| | | toolStripStatusLabel_rotation.Text = $"Rotation:({Rotation.ToString("0")},{RotationF.ToString("0")})"; |
| | | |
| | | //if (!_needPaintAll) |
| | | // return; |
| | | int heightOfBar = showToolBar ? 24 : 0; |
| | | if (!showToolBar) heightOfBar = 0; |
| | | |
| | | |
| | | |
| | | if (e.ClipRectangle != new Rectangle(this.Left, heightOfBar, this.Width, this.Height - heightOfBar - statusStrip1.Height)) return; |
| | | |
| | | |
| | | _needPaintAll = false; |
| | | if (buffer == null || buffer.Width != Width || buffer.Height != Height) |
| | | get |
| | | { |
| | | buffer?.Dispose(); |
| | | buffer = new Bitmap(Width, Height); |
| | | return __needpaintall; |
| | | } |
| | | // 使用缓存绘制,避免在每次重绘时重新计算所有要绘制的元素 |
| | | |
| | | //if (bufferG == null) bufferG = Graphics.FromImage(buffer); |
| | | using (var bufferG = Graphics.FromImage(buffer)) |
| | | //using (var bufferG = e.Graphics) |
| | | set |
| | | { |
| | | // 先将控件的背景填充为白色 |
| | | bufferG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; |
| | | bufferG.Clear(Color.Transparent); |
| | | bufferG.TranslateTransform(Width / 2, Height / 2); |
| | | bufferG.ScaleTransform(Zoom.X, Zoom.Y); |
| | | bufferG.TranslateTransform(-MapCenter.X, -MapCenter.Y); |
| | | |
| | | //if (_NodeColour==null) |
| | | //{ |
| | | // cb_Node_Colour_SelectedIndexChanged(1, new EventArgs()); |
| | | //} |
| | | //if (_LinkColour==null) |
| | | //{ |
| | | // cb_Link_Colour_SelectedIndexChanged(1, new EventArgs()); |
| | | //} |
| | | //BookMark :绘制地图事件 |
| | | Draw(bufferG, _Template); |
| | | |
| | | |
| | | |
| | | if (_newTemplate.network != null) Draw(bufferG, _newTemplate); |
| | | |
| | | var r = 2f / zoom; |
| | | if (_isDragging && DragStartPos != new PointF(0, 0) && mousePosition != new PointF(0, 0)) |
| | | { |
| | | label_center.Text = $"S:{DragStartPos.X}:{DragStartPos.Y} E:{mousePosition.X}:{mousePosition.Y}"; |
| | | var _lastMousePosition = DragStartPos; |
| | | // 绘制矩形 |
| | | var start = new PointF((float)Math.Min(mousePosition.X, _lastMousePosition.X), (float)Math.Min(mousePosition.Y, _lastMousePosition.Y)); |
| | | var size = new SizeF((float)Math.Abs(_lastMousePosition.X - mousePosition.X), (float)Math.Abs(_lastMousePosition.Y - mousePosition.Y)); |
| | | if (size.Width == 0) size.Width = 0.01f; |
| | | if (size.Height == 0) size.Height = 0.01f; |
| | | var rectangle0 = new RectangleF(start, size); |
| | | using (var pen = new Pen(Color.Black, 0.5f * r)) |
| | | { |
| | | bufferG.DrawRectangles(pen, new RectangleF[] { rectangle0 }); |
| | | } |
| | | } |
| | | if (_isPainting) |
| | | { |
| | | using (var pen = new Pen(Color.Black, 1 * r)) |
| | | { |
| | | pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; |
| | | bufferG.DrawLine(pen, WorldPointToMapPoint(_select_junction1), _MousePosition); |
| | | } |
| | | } |
| | | if (_isDrawingPolygon && polygonPoints.Count > 0) |
| | | { |
| | | List<PointF> pf = polygonPoints.ToList(); |
| | | pf.Add(new PointF(mousePosition.X, mousePosition.Y)); |
| | | using (var pen = new Pen(Color.Black, 1 * r)) |
| | | { |
| | | // 绘制多边形虚线边框 |
| | | pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; |
| | | bufferG.DrawLines(pen, pf.ToArray()); |
| | | } |
| | | } |
| | | if (_isSettingBackGroundPictur) |
| | | { |
| | | |
| | | var _lastMousePosition = DragStartPos; |
| | | // 绘制矩形 |
| | | var start = new PointF((float)Math.Min(mousePosition.X, _lastMousePosition.X), (float)Math.Min(mousePosition.Y, _lastMousePosition.Y)); |
| | | var size = new SizeF((float)Math.Abs(_lastMousePosition.X - mousePosition.X), (float)Math.Abs(_lastMousePosition.Y - mousePosition.Y)); |
| | | var rectangle0 = new RectangleF(start, size); |
| | | using (var pen = new Pen(Color.Black, 1 * r)) |
| | | { |
| | | bufferG.DrawRectangles(pen, new RectangleF[] { rectangle0 }); |
| | | } |
| | | } |
| | | |
| | | if (_isMovingObject) |
| | | { |
| | | var newP = _MousePosition; |
| | | //var p = MapPointToWorldPoint(, _OperaNode.Elev); |
| | | var oldP3D = (PointF3D)_undoOldValue; |
| | | var oldP = WorldPointToMapPoint(new PointF(oldP3D.X, oldP3D.Y), oldP3D.Z); |
| | | List<PointF> pf = new List<PointF> { oldP, newP }; |
| | | using (var pen = new Pen(Color.Black, 1 * r)) |
| | | { |
| | | // 绘制多边形虚线边框 |
| | | pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; |
| | | bufferG.DrawLines(pen, pf.ToArray()); |
| | | } |
| | | } |
| | | |
| | | __needpaintall = value; |
| | | } |
| | | // 将生成的画布绘制到控件上 |
| | | e.Graphics.DrawImage(buffer, 0, 0); |
| | | |
| | | } |
| | | <<<<<<< HEAD |
| | | |
| | | ======= |
| | | //protected override void OnPaint(PaintEventArgs e) |
| | | //{ |
| | | // base.OnPaint(e); |
| | | |
| | | // if (float.IsInfinity(zoom)) return; |
| | | |
| | | // //label_center.Text = $"center:({MapCenter.X.ToString("0.00")} ,{MapCenter.Y.ToString("0.00")})"; |
| | | // //label_zoom.Text = $"Zoom:{zoom.ToString("0.000")}"; |
| | | // //toolStripStatusLabel_rotation.Text = $"Rotation:({Rotation.ToString("0")},{RotationF.ToString("0")})"; |
| | | |
| | | // //if (!_needPaintAll) |
| | | // // return; |
| | | // int heightOfBar = showToolBar ? 24 : 0; |
| | | // if (!showToolBar) heightOfBar = 0; |
| | | |
| | | |
| | | |
| | | // if (e.ClipRectangle != new Rectangle(this.Left, heightOfBar, this.map.Width, this.map.Height - heightOfBar - statusStrip1.Height)) return; |
| | | |
| | | |
| | | // _needPaintAll = false; |
| | | // if (buffer == null || buffer.Width != Width || buffer.Height != Height) |
| | | // { |
| | | // buffer?.Dispose(); |
| | | // buffer = new Bitmap(Width, Height); |
| | | // } |
| | | // // 使用缓存绘制,避免在每次重绘时重新计算所有要绘制的元素 |
| | | |
| | | // //if (bufferG == null) bufferG = Graphics.FromImage(buffer); |
| | | // using (var bufferG = Graphics.FromImage(buffer)) |
| | | // //using (var bufferG = e.Graphics) |
| | | // { |
| | | // // 先将控件的背景填充为白色 |
| | | // bufferG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; |
| | | // bufferG.Clear(Color.Transparent); |
| | | // bufferG.TranslateTransform(Width / 2, Height / 2); |
| | | // bufferG.ScaleTransform(Zoom.X, Zoom.Y); |
| | | // bufferG.TranslateTransform(-MapCenter.X, -MapCenter.Y); |
| | | |
| | | // //if (_NodeColour==null) |
| | | // //{ |
| | | // // cb_Node_Colour_SelectedIndexChanged(1, new EventArgs()); |
| | | // //} |
| | | // //if (_LinkColour==null) |
| | | // //{ |
| | | // // cb_Link_Colour_SelectedIndexChanged(1, new EventArgs()); |
| | | // //} |
| | | // //BookMark :绘制地图事件 |
| | | // Draw(bufferG, _Template); |
| | | |
| | | |
| | | |
| | | // if (_newTemplate?.network != null) Draw(bufferG, _newTemplate); |
| | | |
| | | // var r = 2f / zoom; |
| | | // if (_isDragging && DragStartPos!=new PointF(0,0) && mousePosition!=new PointF(0,0)) |
| | | // { |
| | | // label_center.Text = $"S:{DragStartPos.X}:{DragStartPos.Y} E:{mousePosition.X}:{mousePosition.Y}"; |
| | | // var _lastMousePosition = DragStartPos; |
| | | // // 绘制矩形 |
| | | // var start = new PointF((float)Math.Min(mousePosition.X, _lastMousePosition.X), (float)Math.Min(mousePosition.Y, _lastMousePosition.Y)); |
| | | // var size = new SizeF((float)Math.Abs(_lastMousePosition.X - mousePosition.X), (float)Math.Abs(_lastMousePosition.Y - mousePosition.Y)); |
| | | // if (size.Width == 0) size.Width = 0.01f; |
| | | // if (size.Height == 0) size.Height = 0.01f; |
| | | // var rectangle0 = new RectangleF(start, size); |
| | | // using (var pen = new Pen(Color.Black, 0.5f * r)) |
| | | // { |
| | | // bufferG.DrawRectangles(pen, new RectangleF[] { rectangle0 }); |
| | | // } |
| | | // } |
| | | // if (_isPainting) |
| | | // { |
| | | // if (_mouseState == MouseState.新增立管) |
| | | // { |
| | | // var wPos=GetZZWorldPoint(_select_junction1.Position3D, _MousePosition,new Vector3(0,0,1)); |
| | | // using (var pen = new Pen(Color.Black, 1 * r)) |
| | | // { |
| | | // pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; |
| | | // bufferG.DrawLine(pen, WorldPointToMapPoint(_select_junction1), WorldPointToMapPoint(wPos)); |
| | | // } |
| | | // } |
| | | // else |
| | | // { |
| | | // using (var pen = new Pen(Color.Black, 1 * r)) |
| | | // { |
| | | // pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; |
| | | // bufferG.DrawLine(pen, WorldPointToMapPoint(_select_junction1), _MousePosition); |
| | | // } |
| | | // } |
| | | // } |
| | | // if (_isDrawingPolygon && polygonPoints.Count > 0) |
| | | // { |
| | | // List<PointF> pf = polygonPoints.ToList(); |
| | | // pf.Add(new PointF(mousePosition.X, mousePosition.Y)); |
| | | // using (var pen = new Pen(Color.Black, 1 * r)) |
| | | // { |
| | | // // 绘制多边形虚线边框 |
| | | // pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; |
| | | // bufferG.DrawLines(pen, pf.ToArray()); |
| | | // } |
| | | // } |
| | | // if (_isSettingBackGroundPictur) |
| | | // { |
| | | |
| | | // var _lastMousePosition = DragStartPos; |
| | | // // 绘制矩形 |
| | | // var start = new PointF((float)Math.Min(mousePosition.X, _lastMousePosition.X), (float)Math.Min(mousePosition.Y, _lastMousePosition.Y)); |
| | | // var size = new SizeF((float)Math.Abs(_lastMousePosition.X - mousePosition.X), (float)Math.Abs(_lastMousePosition.Y - mousePosition.Y)); |
| | | // var rectangle0 = new RectangleF(start, size); |
| | | // using (var pen = new Pen(Color.Black, 1 * r)) |
| | | // { |
| | | // bufferG.DrawRectangles(pen, new RectangleF[] { rectangle0 }); |
| | | // } |
| | | // } |
| | | |
| | | // if (_isMovingObject) |
| | | // { |
| | | // var newP = _MousePosition; |
| | | // //var p = MapPointToWorldPoint(, _OperaNode.Elev); |
| | | // var oldP3D = (PointF3D)_undoOldValue; |
| | | // var oldP = WorldPointToMapPoint(new PointF(oldP3D.X, oldP3D.Y), oldP3D.Z); |
| | | // List<PointF> pf = new List<PointF> { oldP, newP }; |
| | | // using (var pen = new Pen(Color.Black, 1 * r)) |
| | | // { |
| | | // // 绘制多边形虚线边框 |
| | | // pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; |
| | | // bufferG.DrawLines(pen, pf.ToArray()); |
| | | // } |
| | | // } |
| | | |
| | | // } |
| | | // // 将生成的画布绘制到控件上 |
| | | // e.Graphics.DrawImage(buffer, 0, 0); |
| | | |
| | | //} |
| | | >>>>>>> 0f2ff322746347b91941d936ee27067295e57c76 |
| | | |
| | | PointF[] getCurclePoints(int num) |
| | | { |
| | |
| | | return points; |
| | | } |
| | | |
| | | void Draw(Graphics bufferG, Template template) |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | private void timer_draw_Tick(object sender, EventArgs e) |
| | | { |
| | | 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; |
| | | |
| | | 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<PointF> diametersZoom = new List<PointF>() { 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); |
| | | |
| | | //背景图绘制 |
| | | if (this.mapOption.isShowPic && template != null && File.Exists(template.BackGroundImg_FullPath)) |
| | | _mouseHoverCheckFlag = true; |
| | | if (_timerDraw && map.Status==DrawingStatus.Ready) |
| | | { |
| | | //var gs = bufferG.Save(); |
| | | // 应用矩阵变换以抵消之前的翻转效果 |
| | | //bufferG.ScaleTransform(1 / Zoom.X, 1 / Zoom.Y); |
| | | // 恢复之前保存的绘图状态 |
| | | |
| | | var Cps = new List<PointF> |
| | | { |
| | | template.BackGroundPoint1, |
| | | new PointF(template.BackGroundPoint2.X,template.BackGroundPoint1.Y), |
| | | new PointF(template.BackGroundPoint1.X,template.BackGroundPoint2.Y), |
| | | //template.BackGroundPoint2, |
| | | |
| | | |
| | | }; |
| | | |
| | | |
| | | |
| | | List<PointF> p = new List<PointF>(); |
| | | 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); |
| | | this.map.Invalidate(); |
| | | _timerDraw = false; |
| | | } |
| | | |
| | | |
| | | // 绘制线 |
| | | |
| | | HashSet<long> dict_flow_direction = new HashSet<long>(); |
| | | 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 = getLinkColor(_LinkColour, link); |
| | | } |
| | | Pen pen = link.Status == Hydro.Core.ObjectEnum.StatusType.CLOSED ? penClosed : pen0; |
| | | 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[] { |
| | | getRotatePoint(c.X - valveShapeHeight * r, c.Y + valveShapeHeight * r,c,p1,p2), |
| | | getRotatePoint(c.X - valveShapeHeight * r, c.Y - valveShapeHeight * r,c,p1,p2), |
| | | getRotatePoint(c.X + valveShapeHeight * r, c.Y + valveShapeHeight * r,c,p1,p2), |
| | | getRotatePoint(c.X + valveShapeHeight * r, c.Y - valveShapeHeight * r,c,p1,p2), |
| | | 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[] |
| | | //{ |
| | | // getRotatePoint(c.X - radius - radius, c.Y - radius, c, p1, p2), |
| | | // getRotatePoint(c.X + radius - radius, c.Y - radius, c, p1, p2), |
| | | // getRotatePoint(c.X + radius - radius, c.Y + radius, c, p1, p2), |
| | | // getRotatePoint(c.X - radius - radius, c.Y + radius, c, p1, p2), |
| | | // getRotatePoint(c.X - radius - radius, c.Y - radius, c, p1, p2), |
| | | //}; |
| | | List<PointF> p = new List<PointF>(); |
| | | Cpoints.ForEach(cp => p.Add(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[] { |
| | | getRotatePoint(c.X - valveShapeHeight , c.Y + valveShapeHeight ,c,p1,p2), |
| | | getRotatePoint(c.X - valveShapeHeight , c.Y ,c,p1,p2), |
| | | getRotatePoint(c.X + valveShapeHeight , c.Y ,c,p1,p2), |
| | | getRotatePoint(c.X + valveShapeHeight , c.Y + valveShapeHeight ,c,p1,p2), |
| | | 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 = 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; |
| | | |
| | | bufferG.DrawLines(link.Selected ? penChoosed : pen, new PointF[] { p1, p2 }); |
| | | 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 = 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<PointF> p = new List<PointF>(); |
| | | Cpoints.ForEach(cp => p.Add(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[] { |
| | | getRotatePoint(c.X -activeD* valveShapeHeight , c.Y + valveShapeHeight ,c,p1,p2), |
| | | getRotatePoint(c.X , c.Y ,c,p1,p2), |
| | | getRotatePoint(c.X - activeD*valveShapeHeight , c.Y - valveShapeHeight,c,p1,p2), |
| | | getRotatePoint(c.X + activeD*valveShapeHeight , c.Y - valveShapeHeight,c,p1,p2), |
| | | getRotatePoint(c.X + activeD*valveShapeHeight , c.Y + valveShapeHeight ,c,p1,p2), |
| | | getRotatePoint(c.X - activeD*valveShapeHeight , c.Y + valveShapeHeight ,c,p1,p2), |
| | | }; |
| | | |
| | | bufferG.FillPolygon(link.Selected ? pen_valveChoosed.Brush : pen.Brush, points); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | r = rt; |
| | | |
| | | |
| | | HashSet<long> dict_point = new HashSet<long>(); |
| | | //绘制点 |
| | | penChoosed = new Pen(Color.Green, 1f * r); |
| | | Brush brushChoosed = penChoosed.Brush; |
| | | SolidBrush whiteBrush = new SolidBrush(Color.White); |
| | | |
| | | using (Pen pen = new Pen(Color.FromArgb(255, 0, 0), 1 * r)) |
| | | { |
| | | Brush brush = pen.Brush; |
| | | foreach (NodeViewModel node in _Nodes) |
| | | { |
| | | if (!node.Visible) continue; |
| | | if (node.Elev < minElve || node.Elev >= maxElve) continue; |
| | | float pr = (float)(r * 0.5); |
| | | pr = pr * junction_multiply; |
| | | PointF p = WorldPointToMapPoint(node, template.OffSet); |
| | | if (!isVisible(p)) continue; |
| | | var ps_20 = 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 = 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; |
| | | } |
| | | if (zoomAtMin >= zoom) continue; |
| | | |
| | | if (node.ID == _StartPoint || 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(); |
| | | if (node != null) |
| | | { |
| | | |
| | | //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 = 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 = 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); |
| | | |
| | | } |
| | | } |
| | | //r = r * Link_multiply; |
| | | //using (Pen pen = new Pen(Color.FromArgb(0, 0, 255), 2 * r)) |
| | | //{ |
| | | // foreach (var link in _Links) |
| | | // { |
| | | // if (!link.Visible) continue; |
| | | // if (!isVisible(WorldPointToMapPoint(link))) continue; |
| | | |
| | | // 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 Valve) |
| | | // { |
| | | // if (link.Selected) |
| | | // { |
| | | // var p1 = WorldPointToMapPoint(link.StartNode); |
| | | // var p2 = WorldPointToMapPoint(link.EndNode); |
| | | // var c = new PointF((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2); |
| | | // bufferG.DrawLines(link.Selected ? valveChoosed : pen, new PointF[] { p1, p2 }); |
| | | // bufferG.DrawLines(link.Selected ? valveChoosed : pen, new PointF[] { |
| | | // getRotatePoint(c.X - 3 * r, c.Y + 3 * r,c,p1,p2), |
| | | // getRotatePoint(c.X - 3 * r, c.Y - 2 * r,c,p1,p2), |
| | | // getRotatePoint(c.X + 3 * r, c.Y + 2 * r,c,p1,p2), |
| | | // getRotatePoint(c.X + 3 * r, c.Y - 2 * r,c,p1,p2), |
| | | // getRotatePoint(c.X - 3 * r, c.Y + 2 * r,c,p1,p2), |
| | | |
| | | // }); |
| | | // } |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | } |
| | | 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; |
| | | } |
| | | 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; |
| | | } |
| | | private 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 List<PointF> 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<PointF> nodes = new List<PointF>(); |
| | | 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); |
| | | } |
| | | //nodes.RemoveAt(0); |
| | | //nodes.RemoveAt(nodes.Count - 1); |
| | | |
| | | //// 绘制线段 |
| | | //graphics.DrawLine(Pens.Black, p1, p2); |
| | | |
| | | //// 绘制3等分点和n等分点 |
| | | //foreach (PointF node in node3) |
| | | //{ |
| | | // graphics.FillEllipse(Brushes.Red, node.X - 2, node.Y - 2, 4, 4); |
| | | //} |
| | | //foreach (PointF node in nodes) |
| | | //{ |
| | | // graphics.FillEllipse(Brushes.Blue, node.X - 2, node.Y - 2, 4, 4); |
| | | //} |
| | | return nodes; |
| | | } |
| | | |
| | | |
| | | private 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 PointF[] getRotatePoints(PointF[] ps, PointF center, PointF x, PointF y) |
| | | { |
| | | return ps.ToList().Select(p => getRotatePoint(p, center, x, y)).ToArray(); |
| | | } |
| | | |
| | | |
| | | private 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 new void Invalidate() |
| | | { |
| | | base.Invalidate(); |
| | | _needPaintAll = true; |
| | | PMin_Show = ScreenToMap(new PointF(0, Height)); |
| | | PMax_Show = ScreenToMap(new PointF(Width, 0)); |
| | | |
| | | } |
| | | |
| | | protected override void OnResize(EventArgs e) |
| | |
| | | base.OnResize(e); |
| | | |
| | | // 当控件尺寸改变时,触发重绘 |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | #region 鼠标事件 |
| | | public PointF mouseXY = new PointF(0, 0); |
| | | |
| | | PointF DragStartPos; |
| | | PointF _ClickStartPos; |
| | | PointF RotaStartPos; |
| | | PointF BackGroudPicLeftPos; |
| | | bool _isPanning; |
| | | /// <summary> |
| | | /// 拖拽选择 |
| | | /// </summary> |
| | | bool _isDragging; |
| | | bool _isRotating; |
| | | bool _isPainting; |
| | | public List<IBaseViewModel> selectedObjs = new List<IBaseViewModel>(); |
| | | private List<NodeViewModel> selectedNodes => selectedObjs.FindAll(o => o is NodeViewModel).Select(o => (NodeViewModel)o).ToList(); |
| | | private List<LinkViewModel> selectedLinks => selectedObjs.FindAll(o => o is LinkViewModel).Select(o => (LinkViewModel)o).ToList(); |
| | | private NodeViewModel _OperaNode = null; |
| | | |
| | | |
| | | PointF mousePosition; |
| | | // control+鼠标中间按下缩放 |
| | | bool _isInsertingObject = false; |
| | | bool _isMovingObject = false; |
| | | bool _isPastingObject = false; |
| | | Cursor _lastCursor; |
| | | object _undoOldValue = null; |
| | | private List<PointF> polygonPoints = new List<PointF>(); |
| | | |
| | | public bool Lock2DView = false; |
| | | |
| | | private bool _isDrawingPolygon; |
| | | protected override void OnMouseDown(MouseEventArgs e) |
| | | void mapMouseDown(MouseEventArgs e) |
| | | { |
| | | base.OnMouseDown(e); |
| | | |
| | |
| | | |
| | | polygonPoints.Add(point); |
| | | mousePosition = _MousePosition = ScreenToMap(new PointF(e.X, e.Y)); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | return; |
| | | } |
| | | if (_isDrawingPolygon) |
| | |
| | | } |
| | | |
| | | //移动 |
| | | if (selectedObjs.Count >= 1) //&& selectedObjs[0].isNode()) |
| | | if (_IsEditMode && selectedObjs.Count >= 1) //&& selectedObjs[0].isNode()) |
| | | { |
| | | List<NodeViewModel> nodes = selectedNodes; |
| | | foreach (NodeViewModel node in nodes) |
| | |
| | | |
| | | bool controlDown = false; |
| | | PointF _MousePosition = new PointF(0, 0); |
| | | protected override void OnMouseMove(MouseEventArgs e) |
| | | void mapMouseMove(MouseEventArgs e) |
| | | { |
| | | //base.OnMouseMove(e); |
| | | bool needInvalidate = false; |
| | |
| | | else if (_isRotating) |
| | | { |
| | | mousePosition = _MousePosition; |
| | | bool is下半屏幕 = RotaStartPos.Y >= this.Height / 2; |
| | | if (ModifierKeys != Keys.Alt) Rotation = Rotation0 + ((float)e.X - (float)RotaStartPos.X) * 180 * 2.5 / (float)this.Width * (is下半屏幕 ? 1 : 1); |
| | | if (ModifierKeys != Keys.Shift) RotationF = 俯视角度_start + ((float)e.Y - (float)RotaStartPos.Y) * 180 * 2.5 / (float)this.Height; |
| | | 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) |
| | | { |
| | |
| | | |
| | | |
| | | } |
| | | |
| | | //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); |
| | | |
| | | hoveredObjs.ForEach(o => o.Hovered = false); |
| | | hoveredObjs.Clear(); |
| | | if (obj != null) |
| | | if (hoveredObjs.Count > 0 && hoveredObjs[0] == obj || hoveredObjs.Count == 0 && obj == null) |
| | | { |
| | | obj.Hovered = true; |
| | | hoveredObjs.Add(obj); |
| | | //needInvalidate = false; |
| | | } |
| | | //bool isJunction = obj is NodeViewModel; |
| | | else |
| | | { |
| | | needInvalidate = true; |
| | | hoveredObjs.ForEach(o => o.Hovered = false); |
| | | hoveredObjs.Clear(); |
| | | if (obj != null) |
| | | { |
| | | obj.Hovered = true; |
| | | hoveredObjs.Add(obj); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | if (needInvalidate) this.Invalidate(); |
| | | |
| | | 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; |
| | |
| | | DateTime _lastMouseUp = DateTime.Now; |
| | | int doubleClick_Delay = 500;//毫秒 |
| | | bool recordView = false; |
| | | protected override void OnMouseUp(MouseEventArgs e) |
| | | void mapMouseUp(MouseEventArgs e) |
| | | { |
| | | //BookMark :鼠标抬起事件 |
| | | base.OnMouseUp(e); |
| | |
| | | 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 * Width / size.Width, 1.0f * Height / size.Height); |
| | | 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")}"; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | return; |
| | | } |
| | | if /*放大镜*/(ModifierKeys == Keys.Shift && (e.Button == MouseButtons.Middle || e.Button == MouseButtons.XButton2)) |
| | |
| | | _isSettingBackGroundPictur = false; |
| | | mapOption.isShowPic = true; |
| | | this.Cursor = _lastCursor; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | return; |
| | | } |
| | | if /*插入结构*/(e.Button == MouseButtons.Left && _isInsertingObject) |
| | | { |
| | | var net = _newTemplate.network; |
| | | var net = _newTemplate.network;//clone |
| | | var net0 = _newTemplate.network.DeepCopyByBin<MapViewNetWork>(); |
| | | List<NodeViewModel> nodes = _Nodes.Select(node => (NodeViewModel)node).ToList(); |
| | | float minDist = 100f; |
| | | NodeViewModel minNode = null; |
| | |
| | | |
| | | var p1 = (PointF3D)_undoOldValue; |
| | | var p2 = minNode.Position3D; |
| | | var dd = _newTemplate.OffSet; |
| | | //var dd = _newTemplate.OffSet; |
| | | dx = p2.X - p1.X; |
| | | dy = p2.Y - p1.Y; |
| | | dz = p2.Z - p1.Z; |
| | |
| | | _NewNet.Clear(); |
| | | _OperaNode = null; |
| | | _isInsertingObject = false; |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | return; |
| | | |
| | | var p1 = (PointF3D)_undoOldValue; |
| | |
| | | var list = _Network.Add(net); |
| | | |
| | | var j = _Network.AddPipe(minNode, _OperaNode); |
| | | j.Length = 0.0001f; |
| | | //j.Length = 0.0001f; |
| | | list.Add(j); |
| | | _OperaNode = null; |
| | | _NewNet.Clear(); |
| | |
| | | selectedObjs.AddRange(list); |
| | | |
| | | MapObjectExtensions.AddCommand(_Network, "Add", null, list); |
| | | |
| | | |
| | | |
| | | _isInsertingObject = false; |
| | | |
| | | <<<<<<< HEAD |
| | | |
| | | |
| | | _newTemplate.network = net0; |
| | | _isInsertingObject = true; |
| | | _undoOldValue = new PointF3D(0, 0, 0); |
| | | _OperaNode = _newTemplate.network.Nodes.Find(node => node.ID == _newTemplate.Node1) as NodeViewModel; |
| | | ======= |
| | | //_OperaNode = null; |
| | | //_Network.Nodes.AddRange(net.Nodes); |
| | | //_Network.Links.AddRange(net.Links); |
| | | >>>>>>> 0f2ff322746347b91941d936ee27067295e57c76 |
| | | |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | return; |
| | | } |
| | | if /*多边形选择*/(_isDrawingPolygon && e.Button == MouseButtons.Left && ModifierKeys == Keys.None) |
| | |
| | | }); |
| | | |
| | | } |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | // 结束绘制多边形 |
| | | return; |
| | | } |
| | |
| | | NodeViewModel minNode = null; |
| | | foreach (NodeViewModel node in nodes) |
| | | { |
| | | |
| | | |
| | | PointF mapPos = WorldPointToMapPoint(node); |
| | | PointF currentPoint = MapToScreen(mapPos); |
| | | float currentDist = 0; |
| | |
| | | List<PointF3D> newPositons = selectedNodes.Select(n => n.Position3D).ToList(); |
| | | List<PointF3D> 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<IBaseViewModel>(); |
| | | l.Add(_Network.AddPipe(_OperaNode, minNode)); |
| | | if (l.Count > 0) MapObjectExtensions.AddCommand(_Network, "Add", null, l); |
| | | |
| | | _OperaNode = null; |
| | | _NewNet.Clear(); |
| | | } |
| | |
| | | _OperaNode = null; |
| | | _NewNet.Clear(); |
| | | } |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | return; |
| | | } |
| | | if /*取消移动对象*/(_isMovingObject && !isMouseMoved && e.Button == MouseButtons.Left) |
| | |
| | | { |
| | | //需要把鼠标位置转换为立管的位置,获取鼠标位置的高程 |
| | | |
| | | |
| | | var m = ScreenToVMap(new PointF(e.X, e.Y)); |
| | | z = m.Y; |
| | | p = new PointF(_select_junction1.X, _select_junction1.Y); |
| | | 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 |
| | | { |
| | | getPointAndHeight(e, _select_junction1, out p, out z); |
| | | 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); |
| | | } |
| | | |
| | | |
| | | } |
| | | var l = AddLink(e, isdoubleClick, p, z); |
| | | if (l.Count > 0) MapObjectExtensions.AddCommand(_Network, "Add", null, l); |
| | | |
| | | } |
| | | break; |
| | | } |
| | | _Network.BuildRelation(); |
| | | |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | if /*锁定点选*/(GlobalObject.LockSelect && !isMouseMoved && _mouseState == MouseState.无 && e.Button == MouseButtons.Left) |
| | | { |
| | |
| | | GlobalObject.PropertyForm.SetObjs(new List<IBaseViewModel>() { obj }); |
| | | if (isJunction) _OperaNode = (NodeViewModel)obj; |
| | | mousePosition = new PointF(0, 0); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | |
| | | } |
| | | else |
| | |
| | | GlobalObject.PropertyForm.SetObjs(new List<IBaseViewModel>() { }); |
| | | _OperaNode = null; |
| | | mousePosition = new PointF(0, 0); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | return; |
| | | } |
| | |
| | | if (findNode.Count > 0) _OperaNode = findNode[0] as NodeViewModel; |
| | | if (GlobalObject.PropertyForm != null) |
| | | GlobalObject.PropertyForm.SetObjs(selectedObjs); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | mousePosition = new PointF(0, 0); |
| | | return; |
| | | } |
| | |
| | | } |
| | | if (GlobalObject.PropertyForm != null) |
| | | GlobalObject.PropertyForm.SetObjs(selectedObjs); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | mousePosition = new PointF(0, 0); |
| | | return; |
| | | } |
| | |
| | | } |
| | | if (GlobalObject.PropertyForm != null) |
| | | GlobalObject.PropertyForm.SetObjs(selectedObjs); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | mousePosition = new PointF(0, 0); |
| | | return; |
| | | } |
| | |
| | | _OperaNode = null; |
| | | |
| | | |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | mousePosition = new PointF(0, 0); |
| | | |
| | | |
| | |
| | | |
| | | _OperaNode = null; |
| | | |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | return; |
| | | |
| | |
| | | if (GlobalObject.PropertyForm != null) |
| | | GlobalObject.PropertyForm.SetObjs(selectedObjs); |
| | | |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | mousePosition = new PointF(0, 0); |
| | | } |
| | | else |
| | |
| | | selectedObjs.Add(obj); |
| | | if (GlobalObject.PropertyForm != null) |
| | | GlobalObject.PropertyForm.SetObjs(selectedObjs); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | mousePosition = new PointF(0, 0); |
| | | } |
| | | } |
| | |
| | | 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); |
| | |
| | | IBaseViewModel GetObj_by_ScreenPoint(PointF clickedPoint, float DistLimit = 15f) |
| | | { |
| | | float minDist = float.MaxValue; |
| | | |
| | | |
| | | int minIndex = -1; |
| | | bool isJunction = true; |
| | | IBaseViewModel obj = null; |
| | |
| | | float minDist = float.MaxValue; |
| | | |
| | | int minIndex = -1; |
| | | |
| | | |
| | | IBaseViewModel obj = null; |
| | | List < IBaseViewModel > objs = new List<IBaseViewModel>(); |
| | | List<IBaseViewModel> objs = new List<IBaseViewModel>(); |
| | | for (int i = 0; i < _Nodes.Count; i++) |
| | | { |
| | | var node = _Nodes[i] as NodeViewModel; |
| | |
| | | //float dist = Get_dist(clickedPoint, currentPoint); |
| | | if (dist < minDist && dist <= DistLimit) |
| | | { |
| | | |
| | | |
| | | |
| | | objs.Add(link); |
| | | } |
| | |
| | | /// 鼠标滚轮事件 |
| | | /// </summary> |
| | | /// <param name="e"></param> |
| | | protected override void OnMouseWheel(MouseEventArgs e) |
| | | void mapMouseWheel(MouseEventArgs e) |
| | | { |
| | | base.OnMouseWheel(e); |
| | | mapOption0 = mapOption.Copy(); |
| | |
| | | zoom = Math.Max(MinZoom, Math.Min(MaxZoom, zoom)); |
| | | |
| | | if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | private int _lastMouseX; |
| | |
| | | |
| | | } |
| | | if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | private void tool设置俯视角度_Click(object sender, EventArgs e) |
| | |
| | | jiaodu = Convert.ToDouble(tool.Text); |
| | | RotationF = jiaodu; |
| | | if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | |
| | | Rotation = 0; |
| | | InitCenter(); |
| | | if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | private void 正视图ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | RotationF = 0; |
| | | if (recordView) MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); |
| | | |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | private void 俯视图ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | RotationF = 90; |
| | | MapObjectExtensions.AddCommand(mapOption, "Map", mapOption0, mapOption); |
| | | |
| | | Invalidate(); |
| | | 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 => |
| | |
| | | |
| | | }); |
| | | |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | private void 设置长度ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | MovePointbyLength(l.StartNode, l.EndNode, (float)length); |
| | | } |
| | | |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | void MovePointbyLength(NodeViewModel node1, NodeViewModel node2, float Length) |
| | | { |
| | |
| | | v.Visible = true; |
| | | } |
| | | }); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | #endregion |
| | | |
| | |
| | | { |
| | | _Template = new Template(); |
| | | _Template.network = new MapViewNetWork(); |
| | | |
| | | |
| | | //_Template.network.use_old = false; |
| | | // 获取选中文件的文件路径 |
| | | string filePath = openFileDialog.FileName; |
| | |
| | | #region 绘图工具 |
| | | |
| | | |
| | | MouseState _mouseState = MouseState.无; |
| | | |
| | | public void toolStripButton_新建节点_Click(object sender, EventArgs e) |
| | | { |
| | | _mouseState = MouseState.新增节点; |
| | |
| | | { |
| | | _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) |
| | |
| | | } |
| | | |
| | | |
| | | private List<IBaseViewModel> AddLink(MouseEventArgs e, bool isdoubleClick, PointF p, float z) |
| | | private List<IBaseViewModel> AddLink(PointF e, bool isdoubleClick, PointF p, float z) |
| | | { |
| | | List<IBaseViewModel> l = new List<IBaseViewModel>(); |
| | | var node = GetObj_by_ScreenPoint(new PointF(e.X, e.Y)); |
| | | var node = GetObj_by_ScreenPoint(e); |
| | | if (node != null || isdoubleClick) |
| | | { |
| | | if (node != null && node is NodeViewModel j) |
| | |
| | | { |
| | | _select_junction1 = null; |
| | | _isPainting = false; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | else if (_isDragging) |
| | | { |
| | | _isDragging = false; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | else if (_isPanning) |
| | | { |
| | | _isPanning = false; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | else if (_isRotating) |
| | | { |
| | | Rotation = Rotation0; |
| | | _isRotating = false; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | else if (_isMovingObject) |
| | | { |
| | | _NewNet.Clear(); |
| | | _isMovingObject = false; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | else if (_mouseState != MouseState.无) |
| | | { |
| | |
| | | _NewNet.Clear(); |
| | | _isInsertingObject = false; |
| | | _OperaNode = null; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | else |
| | | { |
| | | _Nodes.ForEach(o => ((NodeViewModel)o).Selected = false); |
| | | _Links.ForEach(o => ((LinkViewModel)o).Selected = false); |
| | | selectedObjs.Clear(); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | if (e.KeyCode == Keys.Delete) |
| | | if (_IsEditMode && e.KeyCode == Keys.Delete) |
| | | { |
| | | DeleteChoosedObj(); |
| | | } |
| | |
| | | selectedObjs.Clear(); |
| | | _Nodes.ForEach(o => { ((NodeViewModel)o).Selected = true; selectedObjs.Add((NodeViewModel)o); }); |
| | | _Links.ForEach(o => { ((LinkViewModel)o).Selected = true; selectedObjs.Add((LinkViewModel)o); }); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | if (e.KeyCode == Keys.C && e.Modifiers == Keys.Control) |
| | | if (_IsEditMode && e.KeyCode == Keys.C && e.Modifiers == Keys.Control) |
| | | { |
| | | 复制ToolStripMenuItem_Click(1, new EventArgs()); |
| | | } |
| | | if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control) |
| | | if (_IsEditMode && e.KeyCode == Keys.V && e.Modifiers == Keys.Control) |
| | | { |
| | | _ClickStartPos = Cursor.Position; |
| | | 粘贴ToolStripMenuItem1_Click(1, new EventArgs()); |
| | | } |
| | | if (e.KeyCode == Keys.D1 && e.Modifiers == Keys.Control) |
| | | if (_IsEditMode && e.KeyCode == Keys.D1 && e.Modifiers == Keys.Control) |
| | | { |
| | | 南北对齐ToolStripMenuItem_Click(1, new EventArgs()); |
| | | |
| | | } |
| | | if (e.KeyCode == Keys.Oemtilde && e.Modifiers == Keys.Control) |
| | | if (_IsEditMode && e.KeyCode == Keys.Oemtilde && e.Modifiers == Keys.Control) |
| | | { |
| | | 东西对齐ToolStripMenuItem_Click(1, new EventArgs()); |
| | | } |
| | | if (e.KeyCode == Keys.D2 && e.Modifiers == Keys.Control) |
| | | if (_IsEditMode && e.KeyCode == Keys.D2 && e.Modifiers == Keys.Control) |
| | | { |
| | | 竖直对齐ToolStripMenuItem_Click(1, new EventArgs()); |
| | | } |
| | | if (e.KeyCode == Keys.D3 && e.Modifiers == Keys.Control) |
| | | if (_IsEditMode && e.KeyCode == Keys.D3 && e.Modifiers == Keys.Control) |
| | | { |
| | | 自动对齐ToolStripMenuItem_Click(1, new EventArgs()); |
| | | } |
| | |
| | | |
| | | private void MapViewer_KeyPress(object sender, KeyPressEventArgs e) |
| | | { |
| | | if (ctrlPressed && e.KeyChar == 'Z' - 64) |
| | | if (_IsEditMode && ctrlPressed && e.KeyChar == 'Z' - 64) |
| | | { |
| | | // 执行相应的操作 |
| | | buttonUndo_Click(sender, e); |
| | |
| | | // 防止默认操作 |
| | | e.Handled = true; |
| | | } |
| | | if (ctrlPressed && e.KeyChar == 'Y' - 64) |
| | | if (_IsEditMode && ctrlPressed && e.KeyChar == 'Y' - 64) |
| | | { |
| | | // 执行相应的操作 |
| | | buttonRedo_Click(sender, e); |
| | |
| | | } |
| | | private void MapViewer_PreKeyPress(object sender, PreviewKeyDownEventArgs e) |
| | | { |
| | | if (e.Control && e.KeyCode == Keys.Z) |
| | | if (_IsEditMode && e.Control && e.KeyCode == Keys.Z) |
| | | { |
| | | ctrlPressed = true; |
| | | // 防止默认操作 |
| | | e.IsInputKey = true; |
| | | |
| | | } |
| | | if (e.Control && e.KeyCode == Keys.Y) |
| | | if (_IsEditMode && e.Control && e.KeyCode == Keys.Y) |
| | | { |
| | | ctrlPressed = true; |
| | | // 防止默认操作 |
| | |
| | | else |
| | | position = obj.Position; |
| | | PointF currentPos = MapToScreen(WorldPointToMapPoint(position, obj.Elev)); |
| | | PointF centerScreen = new PointF(this.Width / 2, this.Height / 2); |
| | | 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, |
| | |
| | | } |
| | | |
| | | |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | public void 删除ToolStripMenuItem_Click(object sender, EventArgs e) |
| | |
| | | var list = _Network.Remove(selectedObjs); |
| | | MapObjectExtensions.AddCommand(_Network, "Remove", null, list); |
| | | selectedObjs.Clear(); |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | #endregion |
| | | |
| | |
| | | { |
| | | _IsEditMode = !_IsEditMode; |
| | | //toolStripComboBox_浏览模式.Text = isEditMode ? "编辑模式" : "浏览模式"; |
| | | LoadData(true); |
| | | //LoadData(true); |
| | | } |
| | | |
| | | private void 浏览模式ToolStripMenuItem_Click(object sender, EventArgs e) |
| | |
| | | var obj = sender as ToolStripItem; |
| | | _IsEditMode = obj.Text == "编辑模式"; |
| | | //toolStripComboBox_浏览模式.Text = isEditMode ? "编辑模式" : "浏览模式"; |
| | | LoadData(true); |
| | | //LoadData(true); |
| | | } |
| | | #endregion |
| | | |
| | |
| | | |
| | | MapObjectExtensions.AddCommand(nodes, "Position", OldPositions, NewPositions); |
| | | |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | |
| | | |
| | | MapObjectExtensions.AddCommand(nodes, "Position3D", OldPositions, NewPositions); |
| | | |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | public static List<PointF3D> ScalePoints(List<PointF3D> points, PointF3D centerPoint, float scale) |
| | |
| | | selectedObjs.Clear(); |
| | | TraversePipeNetwork(objs, null, false); |
| | | selectsValve.ForEach(o => o.Selected = false); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | } |
| | |
| | | selectedObjs.Clear(); |
| | | TraversePipeNetwork(objs, null); |
| | | selectsValve.ForEach(o => o.Selected = false); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | } |
| | |
| | | // objs.ForEach(o => TraversePipeNetworkALL(o, visitedNodes)); |
| | | |
| | | |
| | | // this.Invalidate(); |
| | | // this.SetInvalidated(); |
| | | |
| | | // } |
| | | //} |
| | |
| | | private void 显示节点ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _ShowJunction = true; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 隐藏节点ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _ShowJunction = false; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 大ToolStripMenuItem_Click(object sender, EventArgs e) |
| | |
| | | { |
| | | junction_multiply = 0.4f; |
| | | } |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 显示阀门ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _ShowValve = true; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | |
| | | } |
| | | |
| | | private void 隐藏阀门ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _ShowValve = false; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | |
| | | |
| | | } |
| | |
| | | { |
| | | Link_multiply = 0.4f; |
| | | } |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | public void buttonUndo_Click(object sender, EventArgs e) |
| | | { |
| | | SetInvalidated(); |
| | | SetMapInvalidate(); |
| | | GlobalObject.PropertyForm.propertyGrid.Refresh(); |
| | | MapObjectExtensions.Undo(); |
| | | } |
| | | public void buttonRedo_Click(object sender, EventArgs e) |
| | | { |
| | | SetInvalidated(); |
| | | SetMapInvalidate(); |
| | | GlobalObject.PropertyForm.propertyGrid.Refresh(); |
| | | MapObjectExtensions.Redo(); |
| | | } |
| | |
| | | { |
| | | bool isReplace = false; |
| | | _Network.BuildToInp(_filePath, null, null, false); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 批量一键生成楼层模型 |
| | | /// </summary> |
| | | public void BatchInsertNet(Template temp) |
| | | { |
| | | var nodes = _Nodes.Where(c => c.Elev > 0).Select(node => (NodeViewModel)node).ToList(); |
| | | _undoOldValue = new PointF3D(0, 0, 0); |
| | | _OperaNode = temp.network.Nodes.Find(node => node.ID == temp.Node1) as NodeViewModel; |
| | | //foreach (var item in nodes) |
| | | if (nodes.Any()) |
| | | { |
| | | for (var i = 0; i < nodes.Count(); i++) |
| | | { |
| | | var net = temp.network.DeepCopy(); |
| | | |
| | | float dx, dy, dz; |
| | | var p1 = (PointF3D)_undoOldValue; |
| | | var p2 = nodes[i].Position3D; |
| | | var dd = temp.OffSet; |
| | | dx = p2.X - p1.X; |
| | | dy = p2.Y - p1.Y; |
| | | dz = p2.Z - p1.Z; |
| | | |
| | | net.Nodes.ForEach(n => { ((NodeViewModel)n).Position3D = new PointF3D(n.X + dx, n.Y + dy, n.Elev + dz); }); |
| | | |
| | | var list = _Network.Add(net); |
| | | |
| | | //var j = _Network.AddPipe(nodes[i], _OperaNode); |
| | | //j.Length = 0.0001f; |
| | | //list.Add(j); |
| | | _NewNet.Clear(); |
| | | |
| | | _Network.BuildRelation(); |
| | | |
| | | selectedObjs.ForEach(o => o.Selected = false); |
| | | selectedObjs.Clear(); |
| | | |
| | | //list.ForEach(m => m.Selected = true); |
| | | //selectedObjs.AddRange(list); |
| | | |
| | | MapObjectExtensions.AddCommand(_Network, "Add", null, list); |
| | | } |
| | | |
| | | _OperaNode = null; |
| | | |
| | | //_OperaNode = null; |
| | | //_Network.Nodes.AddRange(net.Nodes); |
| | | //_Network.Links.AddRange(net.Links); |
| | | |
| | | SetMapInvalidate(); |
| | | } |
| | | } |
| | | |
| | |
| | | objs.ForEach(o => TraversePipeNetworkALL(o, visitedNodes)); |
| | | |
| | | |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | } |
| | |
| | | objs = objs.Distinct().ToList(); |
| | | var visitedNodes = new HashSet<NodeViewModel>(); |
| | | objs.ForEach(o => TraversePipeNetworkALL(o, visitedNodes, 1)); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | } |
| | | public void 复制ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (selectedObjs.Count <= 0) return; |
| | | if (selectedNodes.Count <= 0) return; |
| | | _OperaNode = selectedNodes[0]; |
| | | 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; |
| | |
| | | try |
| | | { |
| | | Clipboard.SetText(json); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | catch |
| | | { |
| | |
| | | public void 粘贴ToolStripMenuItem1_Click(object sender, EventArgs e) |
| | | { |
| | | { |
| | | |
| | | var net = new MapViewNetWork(); |
| | | string json = Clipboard.GetText(); |
| | | net.ReadFromJson(json); |
| | | PointF minPoint = new PointF(net.StartPoint.X, net.StartPoint.Y); |
| | | 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); |
| | | net.Nodes.ForEach(obj => |
| | | //var basePoint = MapPointToWorldPoint(ScreenToMap(position, net.StartPoint.Elev), net.StartPoint.Elev); |
| | | var mPos = _MousePosition; |
| | | if (hoveredObjs.Count > 0 && hoveredObjs[0] is NodeViewModel minNode) |
| | | { |
| | | 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); |
| | | MapObjectExtensions.AddCommand(_Network, "Add", null, list); |
| | | Invalidate(); |
| | | |
| | | 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) |
| | |
| | | } |
| | | private void 设为关闭ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | selectedObjs.ForEach(obj => { if (obj is LinkViewModel link) link.Status = StatusType.CLOSED; }); |
| | | Invalidate(); |
| | | selectedObjs.ForEach(obj => { if (obj is LinkViewModel link) link.Status = Hydro.Core.ObjectEnum.StatusType.CLOSED; }); |
| | | SetMapInvalidate(); |
| | | } |
| | | private void 显示全部楼层ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | //this.mapOption.ShowFloor = int.MinValue; |
| | | _Network.MapObjects.ForEach(o => o.Visible = true); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | private void 保存楼层视角ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | List<float> list1 = new List<float>(); |
| | | selectedNodes.ForEach(n => { list.Add(n.X); n.X = selectedNodes[0].X; list1.Add(n.X); }); |
| | | MapObjectExtensions.AddCommand(selectedNodes, "X", list, list1); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | public void 东西对齐ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | List<float> list1 = new List<float>(); |
| | | selectedNodes.ForEach(n => { list.Add(n.Y); n.Y = selectedNodes[0].Y; list1.Add(n.Y); }); |
| | | MapObjectExtensions.AddCommand(selectedNodes, "Y", list, list1); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | public void 竖直对齐ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | List<PointF> list1 = new List<PointF>(); |
| | | selectedNodes.ForEach(n => { list.Add(n.Position); n.Position = selectedNodes[0].Position; list1.Add(n.Position); }); |
| | | MapObjectExtensions.AddCommand(selectedNodes, "Position", list, list1); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | public void 自动对齐ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | } |
| | | |
| | | MapObjectExtensions.AddCommand(selectedNodes, "Position3D", OldPosition3Ds, NewPosition3Ds); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | List<PointF3D> ProjectPointsToLine(List<PointF3D> points) |
| | | { |
| | |
| | | public void 显示隐藏底图ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | mapOption.isShowPic = !mapOption.isShowPic; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | } |
| | | |
| | | private dict<string, dynamic> param = null; |
| | |
| | | public void 清除底图ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | mapOption.isShowPic = false; |
| | | Invalidate(); |
| | | SetMapInvalidate(); |
| | | try |
| | | { |
| | | File.Delete(_Template.BackGroundImg_FullPath); |
| | |
| | | } |
| | | |
| | | }); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | private void 全选ToolStripMenuItem_Click(object sender, EventArgs e) |
| | |
| | | } |
| | | |
| | | }); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | private void 反选ToolStripMenuItem_Click(object sender, EventArgs e) |
| | |
| | | } |
| | | |
| | | }); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | private void 显示状态ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Template.mapOption._ShowStatus = true; |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | private void 隐藏状态ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Template.mapOption._ShowStatus = false; |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | |
| | | } |
| | | private void 显示流向ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Template.mapOption._ShowFlowDirection = true; |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | |
| | | |
| | | |
| | |
| | | private void 隐藏流向ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Template.mapOption._ShowFlowDirection = false; |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | |
| | | |
| | | } |
| | |
| | | o.Visible = false; |
| | | } |
| | | }); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | |
| | | }; |
| | | } |
| | | } |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | |
| | | private void 显示所有隐藏内容ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | _Network.MapObjects.ForEach(o => o.Visible = true); |
| | | this.Invalidate(); |
| | | this.SetMapInvalidate(); |
| | | } |
| | | public void toolStripButton_CalcMiniLoss_Click(object sender, EventArgs e) |
| | | { |
| | |
| | | } |
| | | private void toolStripButton_ClearMinor_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | _Network.ClearMinorLoss(); |
| | | } |
| | | private void 显示流向ToolStripMenuItem1_Click(object sender, EventArgs e) |
| | |
| | | bool _isShowDirection = false; |
| | | private void 颜色分级管理ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | Form_Colour form_Colour = new Form_Colour(_Template.Colours); |
| | | Form_Colour form_Colour = new Form_Colour(_Template.Colours,_Template); |
| | | form_Colour.Show(this); |
| | | } |
| | | Colour _NodeColour = null; |
| | | Colour _LinkColour = null; |
| | | private List<IBaseViewModel> hoveredObjs=new List<IBaseViewModel>(); |
| | | |
| | | private void cb_Node_Colour_Click(object sender, EventArgs e) |
| | | { |
| | | private bool __needpaintall = false; |
| | | |
| | | } |
| | | private void cb_Link_Colour_Click(object sender, EventArgs e) |
| | | { |
| | | |
| | | } |
| | | |
| | | private void cb_Link_Colour_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_Template == null) return; |
| | | mapOption.LinkColourIndex = cb_Link_Colour.SelectedIndex; |
| | | |
| | | var type = cb_Link_Colour.SelectedItem == null ? ColourType.管线流量 : (ColourType)cb_Link_Colour.SelectedItem; |
| | | var Colours = _Template.Colours.FindAll(c => c.Type == type); |
| | | if (Colours.Count == 0) |
| | | { |
| | | _LinkColour = null; |
| | | } |
| | | else |
| | | { |
| | | var cls = Colours.FindAll(cl => cl.isChoosed); |
| | | if (cls.Count >= 1) |
| | | { |
| | | _LinkColour = cls[0]; |
| | | } |
| | | else |
| | | { |
| | | _LinkColour = Colours[0]; |
| | | } |
| | | } |
| | | this.Invalidate(); |
| | | mapOption.ColourLink = type; |
| | | this.SetMapInvalidate(); |
| | | } |
| | | private void cb_Node_Colour_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_Template == null) return; |
| | | mapOption.NodeColourIndex = cb_Node_Colour.SelectedIndex; |
| | | |
| | | var type = cb_Node_Colour.SelectedItem == null ? ColourType.节点自由压力 : (ColourType)cb_Node_Colour.SelectedItem; |
| | | var Colours = _Template.Colours.FindAll(c => c.Type == type); |
| | | if (Colours.Count == 0) |
| | | { |
| | | _NodeColour = null; |
| | | } |
| | | else |
| | | { |
| | | var cls = Colours.FindAll(cl => cl.isChoosed); |
| | | if (cls.Count >= 1) |
| | | { |
| | | _NodeColour = cls[0]; |
| | | } |
| | | else |
| | | { |
| | | _NodeColour = Colours[0]; |
| | | |
| | | } |
| | | } |
| | | this.Invalidate(); |
| | | mapOption.ColourNode = type; |
| | | this.SetMapInvalidate(); |
| | | } |
| | | public class Prompt : Form |
| | | |
| | | private void label_ZZ_Click(object sender, EventArgs e) |
| | | { |
| | | 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; |
| | | } |
| | | //正交模式的全局变量开关 |
| | | _isOrtho = !_isOrtho; |
| | | } |
| | | |
| | | private void 楼层管理ToolStripMenuItem_Click(object sender, EventArgs e) |
| | | { |
| | | if (_Template.Regions == null) |
| | | { |
| | | _Template.Regions = new List<TRegion>(); |
| | | } |
| | | Form_EditFloors form_EditFloors = new Form_EditFloors(_Template.Regions); |
| | | form_EditFloors.Show(this); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | #endregion |
| | | } |
| | | } |