From 4a27caa5a0d8f4eef667cc9ed0d1c01ea7329298 Mon Sep 17 00:00:00 2001 From: lixiaojun <1287241240@qq.com> Date: 星期五, 20 十二月 2024 21:47:27 +0800 Subject: [PATCH] 增加冷却塔匹配 --- WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/04-link/Valve.cs | 255 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 235 insertions(+), 20 deletions(-) diff --git a/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/04-link/Valve.cs b/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/04-link/Valve.cs index b08b5c1..09f24dd 100644 --- a/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/04-link/Valve.cs +++ b/WinFrmUI/Yw.WinFrmUI.Hydro.L2d.Core/01-network/04-link/Valve.cs @@ -16,6 +16,26 @@ public float? LineWidth { get; set; } /// <summary> + /// 鎮仠绾胯壊 + /// </summary> + public Color? HoveredLineColor { get; set; } + + /// <summary> + /// 鎮仠绾垮 + /// </summary> + public float? HoveredLineWidth { get; set; } + + /// <summary> + /// 閫夋嫨绾胯壊 + /// </summary> + public Color? SelectedLineColor { get; set; } + + /// <summary> + /// 閫夋嫨绾垮 + /// </summary> + public float? SelectedLineWidth { get; set; } + + /// <summary> /// 鍥剧墖 /// </summary> public Image Image { get; set; } @@ -30,45 +50,240 @@ /// </summary> public float? Height { get; set; } + /// <summary> + /// 鎮仠鍥剧墖 + /// </summary> + public Image HoveredImage { get; set; } + + /// <summary> + /// 鎮仠瀹藉害 + /// </summary> + public float? HoveredWidth { get; set; } + + /// <summary> + /// 鎮仠楂樺害 + /// </summary> + public float? HoveredHeight { get; set; } + + /// <summary> + /// 閫夋嫨鍥剧墖 + /// </summary> + public Image SelectedImage { get; set; } + + /// <summary> + /// 閫夋嫨瀹藉害 + /// </summary> + public float? SelectedWidth { get; set; } + + /// <summary> + /// 閫夋嫨楂樺害 + /// </summary> + public float? SelectedHeight { get; set; } + + private Coordinate _coordinate { get; set; }//鍧愭爣淇℃伅 + + //鑾峰彇鍧愭爣浣嶇疆 + private Coordinate GetCoordinate(Graphics g) + { + var ws = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Valve.Size.Width; + var hs = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Valve.Size.Height; + var wz = ws / g.PageScale; + var hz = hs / g.PageScale; + var angle = (float)this.StartPosition.AngleClockWise(this.EndPosition); + var xp = this.StartPosition.GetXPoint(this.EndPosition); + var size = new SizeF(xp.X - this.StartPosition.X, 2 * hz); + return Coordinate.GetCoordinate(this.StartPosition, angle, size, StringAlignment.Near, StringAlignment.Center); + } /// <summary> /// 缁樺埗 /// </summary> public override void Draw(Graphics g) { - var fromCachePen = true; - var pen = CacheHelper.ValveLinePen; - if (this.LineColor.HasValue && this.LineWidth.HasValue) + _coordinate = GetCoordinate(g); + + #region 鐢荤嚎 + + if (this.Hovered) { - pen = new Pen(this.LineColor.Value, this.LineWidth.Value); - fromCachePen = false; + var fromCachePen = true; + var pen = CacheHelper.ValveHoveredLinePen; + if (this.HoveredLineColor.HasValue && this.HoveredLineWidth.HasValue) + { + pen = new Pen(this.HoveredLineColor.Value, this.HoveredLineWidth.Value); + fromCachePen = false; + } + var penWidth = pen.Width; + pen.Width = pen.Width / g.PageScale; + g.DrawLine(pen, this.StartPosition, this.EndPosition); + pen.Width = penWidth; + if (!fromCachePen) + { + pen.Dispose(); + } } - g.DrawLine(pen, this.StartPosition, this.EndPosition); - if (!fromCachePen) + else if (this.Selected) { - pen.Dispose(); + var fromCachePen = true; + var pen = CacheHelper.ValveSelectedLinePen; + if (this.SelectedLineColor.HasValue && this.SelectedLineWidth.HasValue) + { + pen = new Pen(this.SelectedLineColor.Value, this.SelectedLineWidth.Value); + fromCachePen = false; + } + var penWidth = pen.Width; + pen.Width = pen.Width / g.PageScale; + g.DrawLine(pen, this.StartPosition, this.EndPosition); + pen.Width = penWidth; + if (!fromCachePen) + { + pen.Dispose(); + } + } + else + { + var fromCachePen = true; + var pen = CacheHelper.ValveLinePen; + if (this.LineColor.HasValue && this.LineWidth.HasValue) + { + pen = new Pen(this.LineColor.Value, this.LineWidth.Value); + fromCachePen = false; + } + var penWidth = pen.Width; + pen.Width = pen.Width / g.PageScale; + g.DrawLine(pen, this.StartPosition, this.EndPosition); + pen.Width = penWidth; + if (!fromCachePen) + { + pen.Dispose(); + } } - var img = CacheHelper.ValveImage; - if (this.Image != null) + + + #endregion + + #region 鐢诲浘鐗� + + if (this.Hovered) { - img = this.Image; + var img = CacheHelper.ValveHoveredImage; + if (this.HoveredImage != null) + { + img = this.HoveredImage; + } + var width = this.HoveredWidth.HasValue ? this.HoveredWidth.Value : CacheHelper.HydroL2d.Valve.HoveredSize.Width; + var height = this.HoveredHeight.HasValue ? this.HoveredHeight.Value : CacheHelper.HydroL2d.Valve.HoveredSize.Height; + var isNewImage = false; + if (img.Width != (int)width || img.Height != (int)height) + { + img = img.CloneC(width, height); + isNewImage = true; + } + + var pt = this.StartPosition.GetCenter(this.EndPosition); + var dx = width / g.PageScale / 2f; + var dy = height / g.PageScale / 2f; + var p0 = new PointF(pt.X - dx, pt.Y - dy); + + g.DrawImage(img, p0); + + if (isNewImage) + { + img.Dispose(); + } } - var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Valve.Width; - var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Valve.Height; - var isNewImage = false; - if (img.Width != (int)width || img.Height != (int)height) + else if (this.Selected) { - img = img.CloneC(width, height); - isNewImage = true; + var img = CacheHelper.ValveSelectedImage; + if (this.SelectedImage != null) + { + img = this.SelectedImage; + } + var width = this.SelectedWidth.HasValue ? this.SelectedWidth.Value : CacheHelper.HydroL2d.Valve.SelectedSize.Width; + var height = this.SelectedHeight.HasValue ? this.SelectedHeight.Value : CacheHelper.HydroL2d.Valve.SelectedSize.Height; + var isNewImage = false; + if (img.Width != (int)width || img.Height != (int)height) + { + img = img.CloneC(width, height); + isNewImage = true; + } + + var pt = this.StartPosition.GetCenter(this.EndPosition); + var dx = width / g.PageScale / 2f; + var dy = height / g.PageScale / 2f; + var p0 = new PointF(pt.X - dx, pt.Y - dy); + + g.DrawImage(img, p0); + + if (isNewImage) + { + img.Dispose(); + } + } + else + { + var img = CacheHelper.ValveImage; + if (this.Image != null) + { + img = this.Image; + } + var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Valve.Size.Width; + var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Valve.Size.Height; + var isNewImage = false; + if (img.Width != (int)width || img.Height != (int)height) + { + img = img.CloneC(width, height); + isNewImage = true; + } + + var pt = this.StartPosition.GetCenter(this.EndPosition); + var dx = width / g.PageScale / 2f; + var dy = height / g.PageScale / 2f; + var p0 = new PointF(pt.X - dx, pt.Y - dy); + + g.DrawImage(img, p0); + + if (isNewImage) + { + img.Dispose(); + } } - g.DrawImage(img, this.StartPosition.GetCenter(this.EndPosition)); - if (isNewImage) + + #endregion + + } + + + /// <summary> + /// 鍖呭惈 + /// </summary> + public override bool Contains(PointF pt) + { + if (_coordinate == null) { - img.Dispose(); + return false; } + var pa = _coordinate.Origin.RotatePointF(pt, _coordinate.Angle, false); + return _coordinate.BeforeRectf.Contains(pa); + } + + /// <summary> + /// 鐩镐氦 + /// </summary> + public override bool Intersect(RectangleF rectf) + { + var positions = this.Positions; + foreach (var position in positions) + { + if (rectf.Contains(position)) + { + return true; + } + } + return false; } -- Gitblit v1.9.3