internal Rect GetRect() { return(new Rect( ModelingHelper.Round(DesignerCanvas.GetLeft(this)), ModelingHelper.Round(DesignerCanvas.GetTop(this)), ModelingHelper.Round(this.ActualWidth), ModelingHelper.Round(this.ActualHeight) )); }
private void UpdateAnchorPosition() { Point point, tangent; var path = this.PathGeometry; path.GetPointAtFractionLength(0, out point, out tangent); this.SourceAnchorAngle = ModelingHelper.ToAngle(-tangent.Y, -tangent.X); this.SourceAnchorPosition = point; path.GetPointAtFractionLength(1, out point, out tangent); this.SinkAnchorAngle = ModelingHelper.ToAngle(tangent.Y, tangent.X); this.SinkAnchorPosition = point; path.GetPointAtFractionLength(0.5, out point, out tangent); this.LabelPosition = this.CenterPoint = point; }
private static PathGeometry GenerateGeometry(List <Point> points) { bool pointsCreated = false; if (points.Count > 0) { pointsCreated = true; //当两个块的边叠在一起时,距离为 0,这时会造成外层的逻辑出错。所以应该做些临时的处理。 if (points.Count == 2) { var start = points[0]; var end = points[1]; if (ModelingHelper.RoundEqual(start, end)) { pointsCreated = false; //points[1] = new Point(end.X + 1, end.Y + 1); } } } if (pointsCreated) { var geometry = new PathGeometry(); PathFigure figure = new PathFigure(); figure.StartPoint = points[0]; points.Remove(points[0]); figure.Segments.Add(new PolyLineSegment(points, true)); geometry.Figures.Add(figure); return(geometry); } return(null); }
private static double Round(double y) { return(ModelingHelper.Round(y)); }
/// <summary> /// 计算某个点到矩形中点的角度。 /// </summary> /// <param name="center"></param> /// <param name="point"></param> /// <returns></returns> private static double AngleFromCenter(Point center, Point point) { return(ModelingHelper.ToAngle(point.Y - center.Y, point.X - center.X)); }
/// <summary> /// 在可视树中找到元素的外层 DesignerCanvas /// </summary> /// <param name="element"></param> /// <returns></returns> public static DesignerCanvas GetOwnerCanvas(DependencyObject element) { return(ModelingHelper.GetVisualParent <DesignerCanvas>(element)); }