/// <summary> /// Compute the rectangle in which the elements should be positioned. /// </summary> /// <returns> /// If this panel is in an <see cref="Adornment"/> and is its <see cref="Node.LocationElement"/>, /// return the <see cref="Adornment.AdornedElement"/>'s size. /// Otherwise return a <c>Rect</c> based on this first child's <c>DesiredSize</c>. /// Only the Width and Height of the Rect matter in the calculations performed by /// <see cref="MeasureOverride"/> and <see cref="ArrangeOverride"/>. /// </returns> protected virtual Rect ComputeBorder() { Adornment ad = Diagram.FindAncestor <Adornment>(this); if (ad != null) { FrameworkElement elt = ad.AdornedElement; if (elt != null && this == ad.LocationElement) { Size sz = ad.GetEffectiveSize(elt); if (sz.Width > 0 && sz.Height > 0) { return(new Rect(0, 0, sz.Width, sz.Height)); } } } Size s = this.DesiredSize; foreach (UIElement child in this.Children) { s = child.DesiredSize; break; } return(new Rect(0, 0, s.Width, s.Height)); }
private static Geometry GetRenderedGeometry(Shape shape, Adornment ad) { Rectangle rectangle = shape as Rectangle; if (rectangle != null) { Size sz = ad.GetEffectiveSize(rectangle); return(new RectangleGeometry() { Rect = new Rect(0, 0, sz.Width, sz.Height), RadiusX = rectangle.RadiusX, RadiusY = rectangle.RadiusY }); } Ellipse ellipse = shape as Ellipse; if (ellipse != null) { Size sz = ad.GetEffectiveSize(ellipse); return(new EllipseGeometry() { Center = new Point(sz.Width / 2, sz.Height / 2), RadiusX = sz.Width / 2, RadiusY = sz.Height / 2 }); } Line line = shape as Line; if (line != null) { return new LineGeometry() { StartPoint = new Point(line.X1, line.Y1), EndPoint = new Point(line.X2, line.Y2) } } ; Polyline polyline = shape as Polyline; if (polyline != null) { PathGeometry g = new PathGeometry(); PathFigure pf = new PathFigure(); PolyLineSegment pls = new PolyLineSegment(); pls.Points = Copy(polyline.Points); //?? not returning a Geometry with the actual points if (polyline.Stretch != Stretch.None) { Size sz = ad.GetEffectiveSize(polyline); pls.Points = ScalePoints(pls.Points, sz, polyline.Stretch); } pf.Segments.Add(pls); if (pls.Points.Count > 0) { pf.StartPoint = pls.Points[0]; } pf.IsClosed = false; pf.IsFilled = false; g.Figures.Add(pf); return(g); } Polygon polygon = shape as Polygon; if (polygon != null) { PathGeometry g = new PathGeometry(); PathFigure pf = new PathFigure(); PolyLineSegment pls = new PolyLineSegment(); pls.Points = Copy(polygon.Points); //?? not returning a Geometry with the actual points if (polygon.Stretch != Stretch.None) { Size sz = ad.GetEffectiveSize(polygon); pls.Points = ScalePoints(pls.Points, sz, polygon.Stretch); } pf.Segments.Add(pls); if (pls.Points.Count > 0) { pf.StartPoint = pls.Points[0]; } pf.IsClosed = true; pf.IsFilled = true; g.Figures.Add(pf); return(g); } Path path = shape as Path; if (path != null) { return(Copy(path.Data)); //?? not returning a Geometry with the actual points } return(null); }
private static Geometry GetRenderedGeometry(Shape shape, Adornment ad) { Rectangle rectangle = shape as Rectangle; if (rectangle != null) { Size sz = ad.GetEffectiveSize(rectangle); return new RectangleGeometry() { Rect = new Rect(0, 0, sz.Width, sz.Height), RadiusX = rectangle.RadiusX, RadiusY = rectangle.RadiusY }; } Ellipse ellipse = shape as Ellipse; if (ellipse != null) { Size sz = ad.GetEffectiveSize(ellipse); return new EllipseGeometry() { Center = new Point(sz.Width/2, sz.Height/2), RadiusX = sz.Width/2, RadiusY = sz.Height/2 }; } Line line = shape as Line; if (line != null) return new LineGeometry() { StartPoint = new Point(line.X1, line.Y1), EndPoint = new Point(line.X2, line.Y2) }; Polyline polyline = shape as Polyline; if (polyline != null) { PathGeometry g = new PathGeometry(); PathFigure pf = new PathFigure(); PolyLineSegment pls = new PolyLineSegment(); pls.Points = Copy(polyline.Points); //?? not returning a Geometry with the actual points if (polyline.Stretch != Stretch.None) { Size sz = ad.GetEffectiveSize(polyline); pls.Points = ScalePoints(pls.Points, sz, polyline.Stretch); } pf.Segments.Add(pls); if (pls.Points.Count > 0) pf.StartPoint = pls.Points[0]; pf.IsClosed = false; pf.IsFilled = false; g.Figures.Add(pf); return g; } Polygon polygon = shape as Polygon; if (polygon != null) { PathGeometry g = new PathGeometry(); PathFigure pf = new PathFigure(); PolyLineSegment pls = new PolyLineSegment(); pls.Points = Copy(polygon.Points); //?? not returning a Geometry with the actual points if (polygon.Stretch != Stretch.None) { Size sz = ad.GetEffectiveSize(polygon); pls.Points = ScalePoints(pls.Points, sz, polygon.Stretch); } pf.Segments.Add(pls); if (pls.Points.Count > 0) pf.StartPoint = pls.Points[0]; pf.IsClosed = true; pf.IsFilled = true; g.Figures.Add(pf); return g; } Path path = shape as Path; if (path != null) return Copy(path.Data); //?? not returning a Geometry with the actual points return null; }