/// <summary> /// 绘制相关的文字信息 /// </summary> /// <param name="dc"></param> /// <param name="startToLine"></param> private void SeText(DrawingContext dc, Line2D startToLine) { string text = ((int)Math.Round(startToLine.Length)).ToString(); Vector2D middle = startToLine.MiddlePoint; Vector2D dir = startToLine.Direction; var rad = dir.AngleFrom(Vector2D.BasisX); var angle = Extension.RadToDeg(rad); if (angle > 90 && angle < 270) { angle = angle + 180; } var md = KernelProperty.MMToPix(middle); RotateTransform rt = new RotateTransform(); rt.Angle = angle; rt.CenterX = md.X; rt.CenterY = md.Y; dc.PushTransform(rt); FormattedText ft = new FormattedText(text, new System.Globalization.CultureInfo(0x0804, false), System.Windows.FlowDirection.LeftToRight, new Typeface("微软雅黑"), 14, Brushes.Blue); dc.DrawText(ft, md); dc.Pop(); }
/// <summary> /// 刷新当前图形元素 /// </summary> public override void Update() { DrawingContext dc = this.RenderOpen(); Pen.Freeze(); //冻结画笔,这样能加快绘图速度 this.DashStyle = new System.Windows.Media.DashStyle(new double[] { 5, 5 }, 10); this.PenColor = Colors.DeepSkyBlue; this.Pen.EndLineCap = PenLineCap.Triangle; ArcSegment arc = new ArcSegment(); arc.IsLargeArc = true; if (start.AngleFrom(end) >= Math.PI) { arc.IsLargeArc = false; } else { arc.IsLargeArc = true; } arc.RotationAngle = 0; arc.Size = new System.Windows.Size(100, 100); arc.Point = KernelProperty.MMToPix(this.end); PathGeometry paths = new PathGeometry(); paths.FillRule = FillRule.EvenOdd; PathFigureCollection pfc = new PathFigureCollection(); PathFigure pf = new PathFigure(); pfc.Add(pf); pf.StartPoint = KernelProperty.MMToPix(this.start); pf.Segments.Add(arc); paths.Figures = pfc; dc.DrawGeometry(Brush, Pen, paths); SeText(dc, Line2D.Create(start, end)); dc.Close(); }