| | |
| | | /// </summary> |
| | | public float? Height { get; set; } |
| | | |
| | | private Coordinate _coordinate { get; set; }//坐标信息 |
| | | |
| | | //获取坐标位置 |
| | | private Coordinate GetCoordinate(Graphics g) |
| | | { |
| | | var ws = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Pump.Size.Width; |
| | | var hs = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Pump.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) |
| | | { |
| | | _coordinate = GetCoordinate(g); |
| | | #region 画线 |
| | | |
| | | var fromCachePen = true; |
| | | var pen = CacheHelper.PumpLinePen; |
| | | 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(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 画图片 |
| | | |
| | | var img = CacheHelper.PumpImage; |
| | | if (this.Image != null) |
| | | { |
| | | img = this.Image; |
| | | } |
| | | var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Pump.Width; |
| | | var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Pump.Height; |
| | | var width = this.Width.HasValue ? this.Width.Value : CacheHelper.HydroL2d.Pump.Size.Width; |
| | | var height = this.Height.HasValue ? this.Height.Value : CacheHelper.HydroL2d.Pump.Size.Height; |
| | | var isNewImage = false; |
| | | if (img.Width != (int)width || img.Height != (int)height) |
| | | { |
| | |
| | | isNewImage = true; |
| | | } |
| | | |
| | | g.DrawImage(img, this.StartPosition.GetCenter(this.EndPosition)); |
| | | 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(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 包含 |
| | | /// </summary> |
| | | public override bool Contains(PointF pt) |
| | | { |
| | | if (_coordinate == null) |
| | | { |
| | | 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; |
| | | |
| | | } |
| | | |
| | | |