Пример #1
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            if (GetValues(this) != null)
            {
                double total = 0.0;
                for (int i = 0; i < InternalChildren.Count; i++)
                {
                    total += (double)(GetValues(this)[i]);
                }
                double offsetAngle = 0.0;

                double radius = finalSize.Width < finalSize.Height ? finalSize.Width / 2 : finalSize.Height / 2;
                //radius -= 2;
                Point beginFigure = new Point(finalSize.Width / 2, finalSize.Height / 2);
                Point lineToBeforeTransform = new Point(beginFigure.X + radius, beginFigure.Y);
                for (int i = 0; i < InternalChildren.Count; i++)
                {
                    ContentControl container = InternalChildren[i] as ContentControl;
                    double wedgeAngle = (double)(GetValues(this)[i]) * 360 / total;
                    RotateTransform rt = new RotateTransform(offsetAngle, beginFigure.X, beginFigure.Y);
                    container.SetValue(PiePanel.BeginFigurePointProperty, beginFigure);
                    container.SetValue(PiePanel.LineToPointProperty, rt.Transform(lineToBeforeTransform));
                    container.SetValue(PiePanel.WedgeAngleProperty, wedgeAngle);
                    offsetAngle += wedgeAngle;
                    Rect r = new Rect(finalSize);
                    container.Arrange(r);
                }
            }
            return finalSize;
        }
Пример #2
0
 public StreamGeometry GetClipGeometry(Size arrangeBounds)
 {
     StreamGeometry clip = new StreamGeometry();
     StreamGeometryContext clipGC = clip.Open();
     clipGC.BeginFigure(BeginFigurePoint, true, true);
     clipGC.LineTo(LineToPoint, false, true);
     Vector v = LineToPoint - BeginFigurePoint;
     RotateTransform rt = new RotateTransform(WedgeAngle, BeginFigurePoint.X, BeginFigurePoint.Y);
     bool isLargeArc = WedgeAngle >180.0;
     clipGC.ArcTo(rt.Transform(LineToPoint), new Size(v.Length, v.Length), WedgeAngle, isLargeArc, SweepDirection.Clockwise, false, true);
     clipGC.Close();
     return clip;
 }
Пример #3
0
 protected override void OnRender(DrawingContext drawingContext)
 {
     base.OnRender(drawingContext);
     Rect rect = new Rect(0.0, 0.0, base.ActualWidth, base.ActualHeight);
     JapaneseTextSource source = new JapaneseTextSource();
     source.Text = this.Text;
     JapaneseTextParagraphProperties textParagraphProperties = this.MakeTextProperties();
     source.JapaneseTextRunProperties = (JapaneseTextRunProperties)textParagraphProperties.DefaultTextRunProperties;
     source.IsVarticalWriting = textParagraphProperties.IsVerticalWriting;
     if (textParagraphProperties.DefaultTextRunProperties.BackgroundBrush != null)
     {
         drawingContext.DrawRectangle(textParagraphProperties.DefaultTextRunProperties.BackgroundBrush, null, rect);
     }
     Rect paddingRect = new Rect(this.Padding.Left, this.Padding.Top, Math.Max(0.0, base.ActualWidth - this.Padding.Left - this.Padding.Right), Math.Max(0.0, base.ActualHeight - this.Padding.Top - this.Padding.Bottom));
     Point center = new Point((paddingRect.Left + paddingRect.Right) / 2.0, (paddingRect.Top + paddingRect.Bottom) / 2.0);
     Point startPosition;
     double paragraphWidth;
     if (textParagraphProperties.IsVerticalWriting)
     {
         Point origin = paddingRect.TopRight;
         Transform transOrigin = new RotateTransform(-90.0, center.X, center.Y);
         startPosition = transOrigin.Transform(origin);
         paragraphWidth = Math.Abs(paddingRect.Height);
         Transform trans = new RotateTransform(90.0, center.X, center.Y);
         drawingContext.PushTransform(trans);
     }
     else
     {
         startPosition = paddingRect.TopLeft;
         paragraphWidth = Math.Abs(paddingRect.Width);
     }
     startPosition.Y += textParagraphProperties.JapaneseTextRunProperties.FontRenderingEmSize;
     int textStorePosition = 0;
     Point linePosition = startPosition;
     TextFormatter formatter = TextFormatter.Create();
     while (textStorePosition < source.Text.Length)
     {
         using (TextLine textLine = formatter.FormatLine(source, textStorePosition, paragraphWidth, textParagraphProperties, null))
         {
             foreach (IndexedGlyphRun indexedrun in textLine.GetIndexedGlyphRuns())
             {
                 if (textParagraphProperties.IsVerticalWriting)
                 {
                     source.UniscribeIndexedGlyphRun(indexedrun);
                     Rect runRect;
                     if (source.GlyphCount != 0 && source.Glyphs[0] != 0)
                     {
                         Point ansiLinePosition = linePosition;
                         ansiLinePosition.Y -= textParagraphProperties.JapaneseTextRunProperties.FontRenderingEmSize / 2.0;
                         runRect = this.DrawIndexedGlyphRun(drawingContext, indexedrun, ansiLinePosition, source, true);
                     }
                     else
                     {
                         Point ansiLinePosition = linePosition;
                         ansiLinePosition.Y -= textParagraphProperties.JapaneseTextRunProperties.FontRenderingEmSize / 10.0;
                         runRect = this.DrawIndexedGlyphRun(drawingContext, indexedrun, ansiLinePosition, source, false);
                     }
                     linePosition.X += runRect.Width;
                 }
                 else
                 {
                     Rect runRect = this.DrawIndexedGlyphRun(drawingContext, indexedrun, linePosition, source, false);
                     linePosition.X += runRect.Width;
                 }
             }
             textStorePosition += textLine.Length;
             linePosition.X = startPosition.X;
             linePosition.Y += textLine.Height;
         }
     }
     if (textParagraphProperties.IsVerticalWriting)
     {
         drawingContext.Pop();
     }
 }
Пример #4
0
        private static Point DrawLineArrowInternal(DrawingContext dc, double half, Pen pen, Brush brush, double x, double y, double angle, ArrowStyle style)
        {
            Point pt;
            bool doRectTransform = angle % 90.0 != 0.0;
            var rt = new RotateTransform(angle, x, y);
            double rx = style.RadiusX;
            double ry = style.RadiusY;
            double sx = 2.0 * rx;
            double sy = 2.0 * ry;

            switch (style.ArrowType)
            {
                default:
                case ArrowType.None:
                    {
                        pt = new Point(x, y);
                    }
                    break;
                case ArrowType.Rectangle:
                    {
                        pt = rt.Transform(new Point(x - sx, y));
                        var rect = new Rect(x - sx, y - ry, sx, sy);
                        if (doRectTransform)
                        {
                            dc.PushTransform(rt);
                            DrawRectangleInternal(dc, half, brush, pen, style.IsStroked, style.IsFilled, ref rect);
                            dc.Pop();
                        }
                        else
                        {
                            var bounds = rt.TransformBounds(rect);
                            DrawRectangleInternal(dc, half, brush, pen, style.IsStroked, style.IsFilled, ref bounds);
                        }
                    }
                    break;
                case ArrowType.Ellipse:
                    {
                        pt = rt.Transform(new Point(x - sx, y));
                        dc.PushTransform(rt);
                        var c = new Point(x - rx, y);
                        DrawEllipseInternal(dc, half, brush, pen, style.IsStroked, style.IsFilled, ref c, rx, ry);
                        dc.Pop();
                    }
                    break;
                case ArrowType.Arrow:
                    {
                        pt = rt.Transform(new Point(x, y));
                        var p11 = rt.Transform(new Point(x - sx, y + sy));
                        var p21 = rt.Transform(new Point(x, y));
                        var p12 = rt.Transform(new Point(x - sx, y - sy));
                        var p22 = rt.Transform(new Point(x, y));
                        DrawLineInternal(dc, half, pen, style.IsStroked, ref p11, ref p21);
                        DrawLineInternal(dc, half, pen, style.IsStroked, ref p12, ref p22);
                    }
                    break;
            }

            return pt;
        }
		public bool RotatedRectContains(Rectangle rect, System.Windows.Point location)
		{
			var rectCorner = new System.Windows.Point(Canvas.GetLeft(rect), Canvas.GetTop(rect));
			var rectRotation = (RotateTransform)rect.RenderTransform;
			var transform = new RotateTransform(-rectRotation.Angle, rectCorner.X + rectRotation.CenterX, rectCorner.Y + rectRotation.CenterY);
			var rotated = transform.Transform(location);
			return rotated.X > rectCorner.X && rotated.X < rectCorner.X + rect.Width && rotated.Y > rectCorner.Y
				   && rotated.Y < rectCorner.Y + rect.Height;
		}
Пример #6
0
        /// <summary>
        /// Intersects a line with a geometry to return the point of intersection
        /// </summary>
        /// <param name="node"></param>
        /// <param name="p"></param>
        /// <param name="centerVector"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        private static Point FindOppositePoint(PathGeometry node, Point p, Vector centerVector, Transform t)
        {
            Vector xaxis = new Point(1, 0) - new Point(0, 0);
            double angleBetween = Vector.AngleBetween(centerVector, xaxis);
            RotateTransform r = new RotateTransform(angleBetween, p.X, p.Y);
            SortedList pointList = new SortedList();

            for (int i = 0; i < node.Figures.Count; i++)
            {
                PathFigure pf = node.Figures[i];
                Point lastPathFigurePoint = r.Transform(pf.StartPoint);
                for (int j = 0; j < pf.Segments.Count; j++)
                {
                    if (pf.Segments[j] is PolyLineSegment)
                    {
                        PolyLineSegment pls = (PolyLineSegment)pf.Segments[j];
                        for (int k = 0; k < pls.Points.Count; k++)
                        {
                            Point point1 = r.Transform(pls.Points[k]);
                            CheckLineSegmentForIntersection(p, point1, lastPathFigurePoint, pointList);
                            lastPathFigurePoint = point1;
                        }
                    }
                    else if (pf.Segments[j] is LineSegment)
                    {
                        LineSegment ls = (LineSegment)pf.Segments[j];
                        Point p1 = r.Transform(ls.Point);
                        Point p2 = lastPathFigurePoint;
                        lastPathFigurePoint = p1;
                        CheckLineSegmentForIntersection(p, p1, p2, pointList);
                    }
                }
            }
            if (pointList.Count < 1)
            {
                return centerVector + p;
            }
            Point returnPt = new Point((double)pointList.GetByIndex(0), p.Y);
            r.Angle = -1 * angleBetween;
            returnPt = r.Transform(returnPt);
            Vector finalVector = returnPt - p;
            if (finalVector.Length > centerVector.Length)
            {
                return centerVector + p;
            }
            return returnPt;
        }
Пример #7
0
        private void ShowSortedItemsInGraph(List<ItemSize> SortedItemList)
        {
            bool hasBoundary = true;
            Brush boundaryBrush = Brushes.Black;
            double boundaryThickness = 0.5;
            Point pieCenter = new Point(PIE_RADIUS, PIE_RADIUS);
            Point startPoint = new Point(PIE_RADIUS, 0);
            
            //Set bitmap effect for the pie graph
#pragma warning disable 0618
            PieGraph.BitmapEffect = new BevelBitmapEffect();
#pragma warning restore 0618

            //Move the center of the pie view to the origin of the canvas (canvas origin is located at the center of the view)
            ScaleTransform scale = new ScaleTransform(absScaleFactor, absScaleFactor);
            TransformGroup trasfm = new TransformGroup();
            trasfm.Children.Add(new TranslateTransform(-PIE_RADIUS, -PIE_RADIUS));
            trasfm.Children.Add(scale);
            PieGraph.RenderTransform = trasfm;

            for (int i = 0; i < SortedItemList.Count; i++)
            {
                var item = SortedItemList[i];
                double angle = 360 * item.Percentage;
                if (angle >= 360) angle = 360 - 1e-5;
                RotateTransform rotate = new RotateTransform(angle, pieCenter.X, pieCenter.Y);
                Point endPoint = rotate.Transform(startPoint);

                //Draw a fan shape
                PathFigure fig = new PathFigure();
                fig.StartPoint = pieCenter;
                fig.IsClosed = hasBoundary;
                fig.Segments.Add(new LineSegment(startPoint, hasBoundary));
                fig.Segments.Add(new ArcSegment(endPoint, new Size(PIE_RADIUS, PIE_RADIUS), 0, angle > 180, SweepDirection.Clockwise, hasBoundary));
                fig.Segments[0].IsSmoothJoin = fig.Segments[1].IsSmoothJoin = true;
                PathGeometry geo = new PathGeometry();
                geo.Figures.Add(fig);

                //Set color and boundary line for current fan shape
                System.Windows.Shapes.Path fan = new System.Windows.Shapes.Path();
                fan.Fill = PieColors[i % PieColors.Length];
                fan.Stroke = boundaryBrush;
                fan.StrokeThickness = boundaryThickness;
                fan.Data = geo;

                //Add tooptip for current fan shape
                ToolTip tip = new ToolTip();
                //A colored rectangle used as an icon of the tooltip
                Rectangle tipIcon = new Rectangle();
                tipIcon.Width = tipIcon.Height = 40;
                tipIcon.Fill = fan.Fill;
                tipIcon.Margin = new Thickness(0, 0, 4, 0);
                //Tooltip message
                TextBox tipMsg = new TextBox();
                string name = (item.IsFolder) ? "[" + item.Name + "]" : item.Name;
                tipMsg.Text = String.Format("{0}\n{1} Bytes\n{2}%", name, item.Size.ToString("n0"), (item.Percentage * 100).ToString("n2"));
                //Assembly tooltip icon and message into a panel and set it to the fan shape tooltip
                StackPanel tipPanel = new StackPanel();
                tipPanel.Orientation = Orientation.Horizontal;
                tipPanel.Children.Add(tipIcon);
                tipPanel.Children.Add(tipMsg);
                tip.Content = tipPanel;
                fan.ToolTip = tip;

                //Add a trigger to current fan so that it is highlighted when mouse is over it
                Trigger trigger = new Trigger();
                trigger.Property = System.Windows.Shapes.Path.IsMouseOverProperty;
                trigger.Value = true;
                trigger.Setters.Add(new Setter(System.Windows.Shapes.Path.OpacityProperty, 0.6));
                Style style = new Style();
                style.Triggers.Add(trigger);
                fan.Style = style;

                //Add current fan to the graph
                PieGraph.Children.Add(fan);
                startPoint = endPoint;
            }
        }
Пример #8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dc"></param>
        /// <param name="line"></param>
        /// <param name="dx"></param>
        /// <param name="dy"></param>
        /// <param name="db"></param>
        /// <param name="r"></param>
        public void Draw(object dc, XLine line, double dx, double dy, ImmutableArray<ShapeProperty> db, Record r)
        {
            var _dc = dc as DrawingContext;

            var style = line.Style;
            if (style == null)
                return;

            double zoom = _state.Zoom;
            double thicknessLine = style.Thickness / zoom;
            double halfLine = thicknessLine / 2.0;
            double thicknessStartArrow = style.StartArrowStyle.Thickness / zoom;
            double halfStartArrow = thicknessStartArrow / 2.0;
            double thicknessEndArrow = style.EndArrowStyle.Thickness / zoom;
            double halfEndArrow = thicknessEndArrow / 2.0;

            // line style
            Tuple<Brush, Pen> lineCache = null;
            Brush fillLine;
            Pen strokeLine;
            if (_enableStyleCache
                && _styleCache.TryGetValue(style, out lineCache))
            {
                fillLine = lineCache.Item1;
                strokeLine = lineCache.Item2;
            }
            else
            {
                fillLine = CreateBrush(style.Fill);
                strokeLine = CreatePen(style, thicknessLine);
                if (_enableStyleCache)
                    _styleCache.Add(style, Tuple.Create(fillLine, strokeLine));
            }

            // start arrow style
            Tuple<Brush, Pen> startArrowCache = null;
            Brush fillStartArrow;
            Pen strokeStartArrow;
            if (_enableArrowStyleCache
                && _arrowStyleCache.TryGetValue(style.StartArrowStyle, out startArrowCache))
            {
                fillStartArrow = startArrowCache.Item1;
                strokeStartArrow = startArrowCache.Item2;
            }
            else
            {
                fillStartArrow = CreateBrush(style.StartArrowStyle.Fill);
                strokeStartArrow = CreatePen(style.StartArrowStyle, thicknessStartArrow);
                if (_enableArrowStyleCache)
                    _arrowStyleCache.Add(style.StartArrowStyle, Tuple.Create(fillStartArrow, strokeStartArrow));
            }

            // end arrow style
            Tuple<Brush, Pen> endArrowCache = null;
            Brush fillEndArrow;
            Pen strokeEndArrow;
            if (_enableArrowStyleCache
                && _arrowStyleCache.TryGetValue(style.EndArrowStyle, out endArrowCache))
            {
                fillEndArrow = endArrowCache.Item1;
                strokeEndArrow = endArrowCache.Item2;
            }
            else
            {
                fillEndArrow = CreateBrush(style.EndArrowStyle.Fill);
                strokeEndArrow = CreatePen(style.EndArrowStyle, thicknessEndArrow);
                if (_enableArrowStyleCache)
                    _arrowStyleCache.Add(style.EndArrowStyle, Tuple.Create(fillEndArrow, strokeEndArrow));
            }

            // line max length
            double x1 = line.Start.X + dx;
            double y1 = line.Start.Y + dy;
            double x2 = line.End.X + dx;
            double y2 = line.End.Y + dy;

            XLine.SetMaxLength(line, ref x1, ref y1, ref x2, ref y2);

            // arrow transforms
            var sas = style.StartArrowStyle;
            var eas = style.EndArrowStyle;
            double a1 = Math.Atan2(y1 - y2, x1 - x2) * 180.0 / Math.PI;
            double a2 = Math.Atan2(y2 - y1, x2 - x1) * 180.0 / Math.PI;
            bool doRectTransform1 = a1 % 90.0 != 0.0;
            bool doRectTransform2 = a2 % 90.0 != 0.0;

            var t1 = new RotateTransform(a1, x1, y1);
            var t2 = new RotateTransform(a2, x2, y2);

            Point pt1;
            Point pt2;

            // draw start arrow
            double radiusX1 = sas.RadiusX;
            double radiusY1 = sas.RadiusY;
            double sizeX1 = 2.0 * radiusX1;
            double sizeY1 = 2.0 * radiusY1;

            switch (sas.ArrowType)
            {
                default:
                case ArrowType.None:
                    {
                        pt1 = new Point(x1, y1);
                    }
                    break;
                case ArrowType.Rectangle:
                    {
                        pt1 = t1.Transform(new Point(x1 - sizeX1, y1));
                        var rect = new Rect(x1 - sizeX1, y1 - radiusY1, sizeX1, sizeY1);
                        if (doRectTransform1)
                        {
                            _dc.PushTransform(t1);
                            DrawRectangleInternal(_dc, halfStartArrow, fillStartArrow, strokeStartArrow, sas.IsStroked, sas.IsFilled, ref rect);
                            _dc.Pop();
                        }
                        else
                        {
                            var bounds = t1.TransformBounds(rect);
                            DrawRectangleInternal(_dc, halfStartArrow, fillStartArrow, strokeStartArrow, sas.IsStroked, sas.IsFilled, ref bounds);
                        }
                    }
                    break;
                case ArrowType.Ellipse:
                    {
                        pt1 = t1.Transform(new Point(x1 - sizeX1, y1));
                        _dc.PushTransform(t1);
                        var c = new Point(x1 - radiusX1, y1);
                        DrawEllipseInternal(_dc, halfStartArrow, fillStartArrow, strokeStartArrow, sas.IsStroked, sas.IsFilled, ref c, radiusX1, radiusY1);
                        _dc.Pop();
                    }
                    break;
                case ArrowType.Arrow:
                    {
                        pt1 = t1.Transform(new Point(x1, y1));
                        var p11 = t1.Transform(new Point(x1 - sizeX1, y1 + sizeY1));
                        var p21 = t1.Transform(new Point(x1, y1));
                        var p12 = t1.Transform(new Point(x1 - sizeX1, y1 - sizeY1));
                        var p22 = t1.Transform(new Point(x1, y1));
                        DrawLineInternal(_dc, halfStartArrow, strokeStartArrow, sas.IsStroked, ref p11, ref p21);
                        DrawLineInternal(_dc, halfStartArrow, strokeStartArrow, sas.IsStroked, ref p12, ref p22);
                    }
                    break;
            }

            // draw end arrow
            double radiusX2 = eas.RadiusX;
            double radiusY2 = eas.RadiusY;
            double sizeX2 = 2.0 * radiusX2;
            double sizeY2 = 2.0 * radiusY2;

            switch (eas.ArrowType)
            {
                default:
                case ArrowType.None:
                    {
                        pt2 = new Point(x2, y2);
                    }
                    break;
                case ArrowType.Rectangle:
                    {
                        pt2 = t2.Transform(new Point(x2 - sizeX2, y2));
                        var rect = new Rect(x2 - sizeX2, y2 - radiusY2, sizeX2, sizeY2);
                        if (doRectTransform2)
                        {
                            _dc.PushTransform(t2);
                            DrawRectangleInternal(_dc, halfEndArrow, fillEndArrow, strokeEndArrow, eas.IsStroked, eas.IsFilled, ref rect);
                            _dc.Pop();
                        }
                        else
                        {
                            var bounds = t2.TransformBounds(rect);
                            DrawRectangleInternal(_dc, halfEndArrow, fillEndArrow, strokeEndArrow, eas.IsStroked, eas.IsFilled, ref bounds);
                        }
                    }
                    break;
                case ArrowType.Ellipse:
                    {
                        pt2 = t2.Transform(new Point(x2 - sizeX2, y2));
                        _dc.PushTransform(t2);
                        var c = new Point(x2 - radiusX2, y2);
                        DrawEllipseInternal(_dc, halfEndArrow, fillEndArrow, strokeEndArrow, eas.IsStroked, eas.IsFilled, ref c, radiusX2, radiusY2);
                        _dc.Pop();
                    }
                    break;
                case ArrowType.Arrow:
                    {
                        pt2 = t2.Transform(new Point(x2, y2));
                        var p11 = t2.Transform(new Point(x2 - sizeX2, y2 + sizeY2));
                        var p21 = t2.Transform(new Point(x2, y2));
                        var p12 = t2.Transform(new Point(x2 - sizeX2, y2 - sizeY2));
                        var p22 = t2.Transform(new Point(x2, y2));
                        DrawLineInternal(_dc, halfEndArrow, strokeEndArrow, eas.IsStroked, ref p11, ref p21);
                        DrawLineInternal(_dc, halfEndArrow, strokeEndArrow, eas.IsStroked, ref p12, ref p22);
                    }
                    break;
            }

            // draw line using points from arrow transforms
            DrawLineInternal(_dc, halfLine, strokeLine, line.IsStroked, ref pt1, ref pt2);
        }
Пример #9
0
        private static DrawingImage GetIcon_Equipment(Brush brushPrimary, Brush brushSecondary)
        {
            DrawingGroup group = new DrawingGroup();

            GeometryDrawing drawing = null;

            #region circle

            drawing = new GeometryDrawing()
            {
                Pen = new Pen()
                {
                    Thickness = 5,
                    DashCap = PenLineCap.Flat,
                    StartLineCap = PenLineCap.Flat,
                    EndLineCap = PenLineCap.Flat,
                    LineJoin = PenLineJoin.Miter,
                    MiterLimit = 10,
                    Brush = brushPrimary,
                },
                Geometry = new EllipseGeometry()
                {
                    Center = new Point(50, 50),
                    RadiusX = 40,
                    RadiusY = 40,
                },
            };

            group.Children.Add(drawing);

            #endregion

            #region center dot

            drawing = new GeometryDrawing()
            {
                Brush = brushPrimary,
                Geometry = new EllipseGeometry()
                {
                    Center = new Point(50, 50),
                    RadiusX = 4,
                    RadiusY = 4,
                },
            };

            group.Children.Add(drawing);

            #endregion

            #region spokes

            Pen pen = new Pen()
            {
                Thickness = 10,
                DashCap = PenLineCap.Flat,
                StartLineCap = PenLineCap.Triangle,
                EndLineCap = PenLineCap.Round,
                LineJoin = PenLineJoin.Miter,
                MiterLimit = 10,
                Brush = brushSecondary,
            };


            Point start = new Point(62.9735178272456, 42.420594688);
            Point end = new Point(73.7538857402056, 36.26268532736);

            RotateTransform rotate = new RotateTransform(0, 50, 50);

            for (int cntr = 0; cntr < 6; cntr++)
            {
                rotate.Angle = 60 * cntr;

                drawing = new GeometryDrawing()
                {
                    Pen = pen,
                    Geometry = new LineGeometry(rotate.Transform(start), rotate.Transform(end)),
                };

                group.Children.Add(drawing);
            }

            #endregion

            DrawingImage retVal = new DrawingImage();
            retVal.Drawing = group;

            return retVal;
        }
Пример #10
0
 public static Geometry GetMarkerGeometry(MarkerType markerType, Point markerOrigin, Size markerSize, double startAngle = 0.0, double sweepAngle = 0.0)
 {
     switch (markerType)
     {
         case MarkerType.Circle:
             return (Geometry)new EllipseGeometry()
             {
                 Center = new Point(markerSize.Width / 2.0 - markerOrigin.X, markerSize.Height / 2.0 - markerOrigin.Y),
                 RadiusX = (markerSize.Width / 2.0),
                 RadiusY = (markerSize.Height / 2.0)
             };
         case MarkerType.Star4:
         case MarkerType.Star5:
         case MarkerType.Star10:
             PointCollection points1 = new PointCollection();
             RotateTransform rotateTransform1 = new RotateTransform();
             rotateTransform1.CenterX = markerSize.Width / 2.0;
             rotateTransform1.CenterY = markerSize.Height / 2.0;
             int num1 = 4;
             if (markerType == MarkerType.Star5)
                 num1 = 5;
             else if (markerType == MarkerType.Star10)
                 num1 = 10;
             for (int index = 0; index < num1 * 2; ++index)
             {
                 Point point = new Point(markerSize.Width / 2.0, index % 2 == 0 ? 0.0 : markerSize.Height / 3.0);
                 rotateTransform1.Angle = (double)index * 360.0 / ((double)num1 * 2.0);
                 point = rotateTransform1.Transform(point);
                 point.X -= markerOrigin.X;
                 point.Y -= markerOrigin.Y;
                 points1.Add(point);
             }
             return VisualUtilities.CreatePolyLineGeometry(points1);
         case MarkerType.Triangle:
             return VisualUtilities.CreatePolyLineGeometry(new PointCollection()
       {
     new Point(markerSize.Width / 2.0 - markerOrigin.X, 0.0 - markerOrigin.Y),
     new Point(markerSize.Width - markerOrigin.X, markerSize.Height - markerOrigin.Y),
     new Point(0.0 - markerOrigin.X, markerSize.Height - markerOrigin.Y)
       });
         case MarkerType.Square:
         case MarkerType.Rectangle:
             return (Geometry)new RectangleGeometry()
             {
                 Rect = new Rect(0.0 - markerOrigin.X, 0.0 - markerOrigin.Y, markerSize.Width, markerSize.Height)
             };
         case MarkerType.Diamond:
             return VisualUtilities.CreatePolyLineGeometry(new PointCollection()
       {
     new Point(markerSize.Width / 2.0 - markerOrigin.X, 0.0 - markerOrigin.Y),
     new Point(markerSize.Width - markerOrigin.X, markerSize.Height / 2.0 - markerOrigin.Y),
     new Point(markerSize.Width / 2.0 - markerOrigin.X, markerSize.Height - markerOrigin.Y),
     new Point(0.0 - markerOrigin.X, markerSize.Height / 2.0 - markerOrigin.Y)
       });
         case MarkerType.Cross:
         case MarkerType.CrossRotated:
             Size size1 = new Size(markerSize.Width / 4.0, markerSize.Height / 4.0);
             Point[] pointArray = new Point[12]
             {
     new Point(markerSize.Width / 2.0 - size1.Width / 2.0 - markerOrigin.X, 0.0 - markerOrigin.Y),
     new Point(markerSize.Width / 2.0 + size1.Width / 2.0 - markerOrigin.X, 0.0 - markerOrigin.Y),
     new Point(markerSize.Width / 2.0 + size1.Width / 2.0 - markerOrigin.X, markerSize.Height / 2.0 - size1.Height / 2.0 - markerOrigin.Y),
     new Point(markerSize.Width - markerOrigin.X, markerSize.Height / 2.0 - size1.Height / 2.0 - markerOrigin.Y),
     new Point(markerSize.Width - markerOrigin.X, markerSize.Height / 2.0 + size1.Height / 2.0 - markerOrigin.Y),
     new Point(markerSize.Width / 2.0 + size1.Width / 2.0 - markerOrigin.X, markerSize.Height / 2.0 + size1.Height / 2.0 - markerOrigin.Y),
     new Point(markerSize.Width / 2.0 + size1.Width / 2.0 - markerOrigin.X, markerSize.Height - markerOrigin.Y),
     new Point(markerSize.Width / 2.0 - size1.Width / 2.0 - markerOrigin.X, markerSize.Height - markerOrigin.Y),
     new Point(markerSize.Width / 2.0 - size1.Width / 2.0 - markerOrigin.X, markerSize.Height / 2.0 + size1.Height / 2.0 - markerOrigin.Y),
     new Point(0.0 - markerOrigin.X, markerSize.Height / 2.0 + size1.Height / 2.0 - markerOrigin.Y),
     new Point(0.0 - markerOrigin.X, markerSize.Height / 2.0 - size1.Height / 2.0 - markerOrigin.Y),
     new Point(markerSize.Width / 2.0 - size1.Width / 2.0 - markerOrigin.X, markerSize.Height / 2.0 - size1.Height / 2.0 - markerOrigin.Y)
             };
             PointCollection points2 = new PointCollection();
             if (markerType == MarkerType.CrossRotated)
             {
                 RotateTransform rotateTransform2 = new RotateTransform();
                 rotateTransform2.Angle = 45.0;
                 rotateTransform2.CenterX = markerSize.Width / 2.0 - markerOrigin.X;
                 rotateTransform2.CenterY = markerSize.Height / 2.0 - markerOrigin.Y;
                 for (int index = 0; index < pointArray.Length; ++index)
                     points2.Add(rotateTransform2.Transform(pointArray[index]));
             }
             else
             {
                 for (int index = 0; index < pointArray.Length; ++index)
                     points2.Add(pointArray[index]);
             }
             return VisualUtilities.CreatePolyLineGeometry(points2);
         case MarkerType.Trapezoid:
             Size size2 = new Size(markerSize.Width / 3.0, markerSize.Height / 3.0);
             return VisualUtilities.CreatePolyLineGeometry(new PointCollection()
       {
     new Point(size2.Width - markerOrigin.X, 0.0 - markerOrigin.Y),
     new Point(markerSize.Width - size2.Width - markerOrigin.X, 0.0 - markerOrigin.Y),
     new Point(markerSize.Width - markerOrigin.X, markerSize.Height - markerOrigin.Y),
     new Point(0.0 - markerOrigin.X, markerSize.Height - markerOrigin.Y)
       });
         case MarkerType.Pentagon:
             PointCollection points3 = new PointCollection();
             RotateTransform rotateTransform3 = new RotateTransform();
             rotateTransform3.CenterX = markerSize.Width / 2.0 - markerOrigin.X;
             rotateTransform3.CenterY = markerSize.Height / 2.0 - markerOrigin.Y;
             int num2 = 5;
             for (int index = 0; index < num2; ++index)
             {
                 Point point = new Point(markerSize.Width / 2.0 - markerOrigin.X, 0.0 - markerOrigin.Y);
                 rotateTransform3.Angle = (double)index * 360.0 / (double)num2;
                 point = rotateTransform3.Transform(point);
                 points3.Add(point);
             }
             return VisualUtilities.CreatePolyLineGeometry(points3);
         case MarkerType.Wedge:
             Size size3 = new Size(markerSize.Width / 3.0, markerSize.Height / 3.0);
             return VisualUtilities.CreatePolyLineGeometry(new PointCollection()
       {
     new Point(markerSize.Width / 2.0 - markerOrigin.X, 0.0 - markerOrigin.Y),
     new Point(markerSize.Width - markerOrigin.X, size3.Height - markerOrigin.Y),
     new Point(markerSize.Width - markerOrigin.X, markerSize.Height - markerOrigin.Y),
     new Point(0.0 - markerOrigin.X, markerSize.Height - markerOrigin.Y),
     new Point(0.0 - markerOrigin.X, size3.Height - markerOrigin.Y)
       });
         case MarkerType.PieSlice:
             if (sweepAngle >= 360.0)
                 return (Geometry)new EllipseGeometry()
                 {
                     Center = new Point(markerSize.Width / 2.0 - markerOrigin.X, markerSize.Height / 2.0 - markerOrigin.Y),
                     RadiusX = (markerSize.Width / 2.0),
                     RadiusY = (markerSize.Height / 2.0)
                 };
             Point point1 = new Point(markerSize.Width / 2.0 - markerOrigin.X, markerSize.Height / 2.0 - markerOrigin.Y);
             Point point2 = new Point(point1.X, point1.Y - markerSize.Height / 2.0);
             Point point3 = VisualUtilities.RotatePointBy(point2, startAngle);
             Point point4 = VisualUtilities.RotatePointBy(point2, startAngle + sweepAngle);
             PathFigure pathFigure = new PathFigure()
             {
                 StartPoint = VisualUtilities.ShiftPoint(point1)
             };
             pathFigure.Segments.Add((PathSegment)new LineSegment()
             {
                 Point = VisualUtilities.ShiftPoint(point3)
             });
             pathFigure.Segments.Add((PathSegment)new ArcSegment()
             {
                 IsLargeArc = (sweepAngle >= 180.0),
                 SweepDirection = SweepDirection.Clockwise,
                 Size = new Size(markerSize.Width / 2.0, markerSize.Height / 2.0),
                 Point = VisualUtilities.ShiftPoint(point4)
             });
             pathFigure.Segments.Add((PathSegment)new LineSegment()
             {
                 Point = VisualUtilities.ShiftPoint(point1)
             });
             return (Geometry)new PathGeometry()
             {
                 Figures = {
       pathFigure
     }
             };
         default:
             return (Geometry)null;
     }
 }
Пример #11
0
        private void DrawCar(Map map)
        {
            if (lastCar != null)
                Canvas_trackPlanner.Children.Remove(lastCar);

            const double CAR_WIDTH = 55;
            const double CAR_HEIGHT = 25;
            const double FRONT_SHOWER_LENTH = 10;

            System.Windows.Shapes.Polyline car = new Polyline();
            car.StrokeThickness = 7;
            car.Stroke = new SolidColorBrush(Colors.Red);
            car.Points = new PointCollection() {
                new Point(map.car.x + CAR_WIDTH / 2, map.car.y + CAR_HEIGHT / 2),
                new Point(map.car.x - CAR_WIDTH / 2, map.car.y + CAR_HEIGHT / 2),
                new Point(map.car.x - CAR_WIDTH / 2, map.car.y - CAR_HEIGHT / 2),
                new Point(map.car.x + CAR_WIDTH / 2, map.car.y - CAR_HEIGHT / 2),
                new Point(map.car.x + CAR_WIDTH / 2, map.car.y),
                new Point(map.car.x + CAR_WIDTH + FRONT_SHOWER_LENTH / 2, map.car.y),
                new Point(map.car.x + CAR_WIDTH / 2, map.car.y),
                new Point(map.car.x + CAR_WIDTH / 2, map.car.y + CAR_HEIGHT / 2)};

            RotateTransform rt = new RotateTransform(map.car.angle, map.car.x, map.car.y);

            car.Points = new PointCollection(car.Points.Select(x => rt.Transform(x)));
            Canvas_trackPlanner.Children.Add(car);

            lastCar = car;
        }
Пример #12
0
 public XYLabelsPanel.LabelMeasureResult Measure(double angle, bool staggered, bool tryLabelWrap, double gap)
 {
     double offset = 0.0;
     double marginLeft = 0.0;
     double marginRight = 0.0;
     bool hasCollisions = false;
     bool flag = false;
     double availableLenght = this.Parent.AvailableSizeInMeasureCycle.Width;
     if (staggered)
     {
         List<AxisLabelControl> firstLevel = new List<AxisLabelControl>();
         List<AxisLabelControl> secondLevel = new List<AxisLabelControl>();
         EnumerableFunctions.ForEachWithIndex<AxisLabelControl>((IEnumerable<AxisLabelControl>)this.Elements, (Action<AxisLabelControl, int>)((label, index) =>
       {
           if (index % 2 > 0)
               secondLevel.Add(label);
           else
               firstLevel.Add(label);
       }));
         XYLabelsPanel.LabelMeasureInfo labelMeasureInfo1 = new XYLabelsPanel.LabelMeasureInfo(this.Parent, this.Level, (IList<AxisLabelControl>)firstLevel);
         XYLabelsPanel.LabelMeasureInfo labelMeasureInfo2 = new XYLabelsPanel.LabelMeasureInfo(this.Parent, this.Level, (IList<AxisLabelControl>)secondLevel);
         XYLabelsPanel.LabelMeasureResult firstInfo = labelMeasureInfo1.Measure(0.0, false, false, gap * 2.0);
         XYLabelsPanel.LabelMeasureResult labelMeasureResult = labelMeasureInfo2.Measure(0.0, false, false, gap * 2.0);
         secondLevel.ForEach((Action<AxisLabelControl>)(label => XYLabelsPanel.SetLevelOffset((UIElement)label, firstInfo.Offset)));
         offset = firstInfo.Offset + labelMeasureResult.Offset;
         marginLeft = Math.Max(firstInfo.MarginLeft, labelMeasureResult.MarginLeft);
         marginRight = Math.Max(firstInfo.MarginRight, labelMeasureResult.MarginRight);
         hasCollisions = firstInfo.HasCollisions || labelMeasureResult.HasCollisions || firstInfo.StaggeredCollisions || labelMeasureResult.StaggeredCollisions || marginRight + marginLeft > availableLenght * 0.35;
         angle = 0.0;
     }
     else
     {
         if (angle == 0.0 && tryLabelWrap)
             this.EvaluateWrapFlag();
         this.PrepareLabels(angle);
         if (this.ClientRectangles.Count > 0)
         {
             offset = Enumerable.Max(Enumerable.Select<Rect, double>((IEnumerable<Rect>)this.ClientRectangles, (Func<Rect, double>)(r => r.Height)));
             List<Rect> list1 = this.AdjustRectanglesToAvailableLength(this.ClientRectangles, this.AngleOffsets, availableLenght, gap);
             if (!this.Parent.Presenter.IsScaleZoomed)
             {
                 list1.ForEach((Action<Rect>)(r =>
                {
                    marginLeft = Math.Max(Math.Max(0.0, marginLeft), -r.Left);
                    marginRight = Math.Max(Math.Max(0.0, marginRight), r.Right - availableLenght);
                }));
                 marginLeft = Math.Ceiling(double.IsNaN(marginLeft) ? 0.0 : marginLeft);
                 marginRight = Math.Ceiling(double.IsNaN(marginRight) ? 0.0 : marginRight);
             }
             else if (!(this.Parent.Axis.Scale is CategoryScale))
             {
                 list1.ForEach((Action<Rect>)(r => marginLeft = Math.Max(Math.Max(0.0, marginLeft), r.Width / 2.0)));
                 marginLeft = Math.Ceiling(double.IsNaN(marginLeft) ? 0.0 : marginLeft);
                 marginRight = marginLeft;
             }
             double availableLenght1 = Math.Max(0.0, availableLenght - (marginRight + marginLeft));
             List<Rect> list2;
             if (!DoubleHelper.EqualsWithPrecision(Math.Abs(angle % 90.0), 0.0))
             {
                 List<Rect> list3 = this.AdjustRectanglesToAvailableLength(this.ContentRectangles, (IList<Point>)null, availableLenght1, gap);
                 RotateTransform transform = new RotateTransform()
                 {
                     Angle = angle
                 };
                 list2 = Enumerable.ToList<Rect>(Enumerable.Select<Rect, Rect>((IEnumerable<Rect>)list3, (Func<Rect, Rect>)(r =>
               {
                   Point point = transform.Transform(new Point(r.X + r.Width / 2.0, r.Y + r.Height / 2.0));
                   return new Rect(point.X, point.Y, r.Width, r.Height);
               })));
             }
             else
                 list2 = this.AdjustRectanglesToAvailableLength(this.ClientRectangles, this.AngleOffsets, availableLenght1, gap);
             hasCollisions = this.TextWrapFlagResult != TextWrapping.Wrap && this.HasCollisions((IList<Rect>)list2, angle != 0.0);
             if (!DoubleHelper.EqualsWithPrecision(Math.Abs(angle % 90.0), 0.0))
                 hasCollisions = hasCollisions || marginRight + marginLeft > availableLenght * 0.35;
             flag = hasCollisions || angle != 0.0;
             if (!flag && list2.Count > 1)
             {
                 double distance = Enumerable.Min(Enumerable.Zip<Rect, Rect, double>((IEnumerable<Rect>)list2, Enumerable.Skip<Rect>((IEnumerable<Rect>)list2, 1), (Func<Rect, Rect, double>)((prev, next) => Math.Abs(next.X + next.Width / 2.0 - (prev.X + prev.Width / 2.0)))));
                 flag = Enumerable.Any<Rect>((IEnumerable<Rect>)list2, (Func<Rect, bool>)(r => r.Width > distance));
             }
         }
     }
     return new XYLabelsPanel.LabelMeasureResult(offset, marginLeft, marginRight, hasCollisions, angle, staggered)
     {
         StaggeredCollisions = flag
     };
 }