// TODO: we should interpret the shape/style/color attributes ...
        public void Draw(NodeLayout layoutState)
        {
            var style = myPresentation.GetPropertySetFor <NodeStyle>().Get(Owner.Id);
            var label = myPresentation.GetPropertySetFor <Caption>().Get(Owner.Id);

            Visual = new DrawingVisual();
            var dc = Visual.RenderOpen();

            if (style.Shape.Equals("rectangle", StringComparison.OrdinalIgnoreCase))
            {
                var rect = layoutState.GetBoundingBox();

                dc.DrawRectangle(style.FillColor, new Pen(style.BorderColor, 0.016), rect);
            }
            else
            {
                dc.DrawEllipse(style.FillColor, new Pen(style.BorderColor, 0.016), layoutState.Center, layoutState.Width, layoutState.Height);
            }

            var tx = new FormattedText(label.DisplayText,
                                       CultureInfo.InvariantCulture,
                                       FlowDirection.LeftToRight,
                                       myFont,
                                       layoutState.Height * 0.7, Brushes.Black);

            dc.DrawText(tx, new Point(layoutState.Center.X - tx.Width / 2, layoutState.Center.Y - tx.Height / 2));

            dc.Close();

            Visual.SetValue(GraphItemProperty, Owner);
        }
        public void Draw(EdgeLayout layoutState)
        {
            var styleState = myPresentation.GetPropertySetFor <EdgeStyle>().Get(Owner.Id);
            var label      = myPresentation.GetPropertySetFor <Caption>().Get(Owner.Id);

            var stream  = new StreamGeometry();
            var context = stream.Open();

            context.BeginFigure(layoutState.Points.First(), false, false);

            context.PolyBezierTo(layoutState.Points.Skip(1).ToList(), true, false);

            // draw arrow head
            {
                var start = layoutState.Points.Last();
                var v     = start - layoutState.Points.ElementAt(layoutState.Points.Count() - 2);
                v.Normalize();

                start = start - v * 0.05;
                context.BeginFigure(start + v * 0.18, true, true);

                // Rotate 90°
                double t = v.X;
                v.X = v.Y;
                v.Y = -t;

                context.LineTo(start + v * 0.06, true, true);
                context.LineTo(start + v * -0.06, true, true);

                context.Close();
            }

            var pen = new Pen(styleState.Color, 1);

            SetLineThickness(pen);

            // http://stackoverflow.com/questions/1755520/improve-drawingvisual-renders-speed
            Visual = new DrawingVisual();
            var dc = Visual.RenderOpen();

            dc.DrawGeometry(pen.Brush, pen, stream);

            if (label.DisplayText != label.OwnerId)
            {
                var sourceLayoutState = myPresentation.GetModule <IGraphLayoutModule>().GetLayout(Owner.Source);

                var tx = new FormattedText(label.DisplayText,
                                           CultureInfo.InvariantCulture,
                                           FlowDirection.LeftToRight,
                                           myFont,
                                           sourceLayoutState.Height * 0.5, Brushes.Black);

                dc.DrawText(tx, new Point(layoutState.LabelPosition.X - tx.Width, layoutState.LabelPosition.Y - tx.Height));
            }

            dc.Close();

            Visual.SetValue(GraphItemProperty, Owner);
        }
Beispiel #3
0
        private void LoadNode()
        {
            string nodeId = parser.ReadString(); // NodeId
            Point  center = parser.ReadPoint();

            double rx    = parser.ReadDouble() / 2;
            double ry    = parser.ReadDouble() / 2;
            string label = parser.ReadString();
            // TODO - Átírni
            string borderStyle = parser.ReadString();
            string shape       = parser.ReadString();
            string borderColor = parser.ReadString();
            var    brush       = parser.ReadString();

            bool doubleLine = borderColor == "gray" ? true : false;

            Brush fill = GetCachedBrush(brush);

            DrawingVisual  visual = new DrawingVisual();
            DrawingContext dc     = visual.RenderOpen();



            if (shape == "ellipse")
            {
                dc.DrawEllipse(fill, outline, center, rx, ry);
                if (doubleLine)
                {
                    dc.DrawEllipse(fill, outline, center, rx - 0.05, ry - 0.05);
                }
            }
            else if (shape == "box")
            {
                dc.DrawRectangle(fill, outline, new Rect(center.X - rx, center.Y - ry, rx * 2.0, ry * 2.0));
                if (doubleLine)
                {
                    dc.DrawRectangle(fill, outline, new Rect(center.X - rx + 0.05, center.Y - ry + 0.05, rx * 2.0 - 0.1, ry * 2.0 - 0.1));
                }
            }

            FormattedText tx = new FormattedText(label,
                                                 CultureInfo.InvariantCulture,
                                                 FlowDirection.LeftToRight,
                                                 font,
                                                 ry * 0.7, Brushes.Black);

            dc.DrawText(tx, new Point(center.X - tx.Width / 2, center.Y - tx.Height / 2));
            dc.Close();

            visual.SetValue(FrameworkElement.TagProperty, nodeId);

            graph.Children.Add(visual);

            ++node_count;
        }
Beispiel #4
0
        private void LoadGraph(IEnumerable <Node> Nodes, IEnumerable <Edge> Edges, BitmapFrame Frame = null, double PenSize = 0, double [] BoundingBox = null)
        {
            if (Frame != null)
            {
                DrawingVisual drawingVisual = new DrawingVisual();
                using (DrawingContext drawingContext = drawingVisual.RenderOpen())
                {
                    drawingContext.DrawImage(Frame, new Rect(0, 0, Frame.Width, Frame.Height));
                }

                graph.Children.Add(drawingVisual);
            }

            if (BoundingBox == null)
            {
                BBMinX = -1;
                BBMinY = -1;
                BBMaxX = -1;
                BBMaxY = -1;
            }
            else if (BoundingBox.Length == 4)
            {
                BBMinX = BoundingBox[0];
                BBMinY = BoundingBox[1];
                BBMaxX = BoundingBox[2];
                BBMaxY = BoundingBox[3];
                DrawingVisual  visual          = new DrawingVisual();
                DrawingContext dc              = visual.RenderOpen();
                Pen            pen             = new Pen(Brushes.Maroon, 0.2 + PenSize);
                Brush          fill            = Brushes.Transparent;
                Rect           BoundingBoxRect = new Rect(new Point(BBMinX, BBMinY), new Point(BBMaxX, BBMaxY));
                dc.DrawRectangle(fill, pen, BoundingBoxRect);
                dc.Close();
                visual.SetValue(FrameworkElement.TagProperty, $"BBox_{01}");
                graph.Children.Add(visual);
            }

            for (int i = 0; i < Nodes.Count(); i++)
            {
                LoadNode(Nodes.ElementAt(i), i);
            }

            if (Frame == null)
            {
                PenSize = 0;
            }

            for (int i = 0; i < Edges.Count(); i++)
            {
                LoadEdge(Edges.ElementAt(i), i, PenSize);
            }
        }
Beispiel #5
0
        SaveVertexOnDrawingVisual
        (
            IVertex oVertex,
            DrawingVisual oDrawingVisual
        )
        {
            Debug.Assert(oVertex != null);
            Debug.Assert(oDrawingVisual != null);
            AssertValid();

            // DrawingVisual has no Tag property, so use FrameworkElement's Tag
            // property as an attached property.

            oDrawingVisual.SetValue(FrameworkElement.TagProperty, oVertex);
        }
Beispiel #6
0
        private void DrawNode(NodeLayout node)
        {
            if (_nodeContents.TryGetValue(node, out var nodeContent))
            {
                if (node.IsSubGraph)
                {
                    nodeContent.Arrange(new Rect(node.Left, node.Top, node.Width, node.Height));

                    nodeContent.Width  = node.Width;
                    nodeContent.Height = node.Height;
                }
                nodeContent.SetValue(FrameworkElement.TagProperty, node);
                _view._hostCanvas.Children.Add(nodeContent);
                nodeContent.MouseMove  += NodeContent_MouseMove;
                nodeContent.MouseLeave += NodeContent_MouseLeave;
            }
            else
            {
                var            visual         = new DrawingVisual();
                DrawingContext drawingContext = visual.RenderOpen();
                if (!_view.OnDrawNode(node, drawingContext))
                {
                    Rect rect = new Rect(new Point(node.Position.X - node.Size.X / 2, node.Position.Y - node.Size.Y / 2), new Size(node.Size.X, node.Size.Y));

                    drawingContext.DrawRectangle(brushes[brushCounter], node.IsSubGraph ? EdgeTemplate.DefaultPen : null, rect);

                    ++brushCounter;
                    if (brushCounter >= brushes.Length)
                    {
                        brushCounter = 0;
                    }
                }
                drawingContext.Close();
                visual.SetValue(FrameworkElement.TagProperty, node);
                _visuals.Children.Add(visual);
            }

            if (node.IsSubGraph)
            {
                foreach (var childNode in node.Nodes)
                {
                    this.DrawNode(childNode);
                }
            }
        }
Beispiel #7
0
        private void LoadEdge(Edge edge, int EdgeId, double PenSize = 0)
        {
            DrawingVisual  visual = new DrawingVisual();
            DrawingContext dc     = visual.RenderOpen();

            Pen  pen      = new Pen(Brushes.Red, 0.05 + PenSize);
            Edge edgeCopy = ToBoundingBoxPoint(edge);

            if (IsInBoundingBox(new Point(edgeCopy.A.X, edgeCopy.A.Y)) == 0 && IsInBoundingBox(new Point(edgeCopy.B.X, edgeCopy.B.Y)) == 0)
            {
                dc.DrawLine(pen, new Point(edgeCopy.A.X, edgeCopy.A.Y), new Point(edgeCopy.B.X, edgeCopy.B.Y));
            }

            dc.Close();
            visual.SetValue(FrameworkElement.TagProperty, $"Edge_{EdgeId}");

            graph.Children.Add(visual);
            ++edge_count;
        }
Beispiel #8
0
        private void LoadNode(Node NodePoint, int NodeId)
        {
            Brush fill = Brushes.Transparent;

            if (Math.Abs(NodePoint.Orientation) >= 0.1)
            {
                fill = Brushes.Blue;
            }

            DrawingVisual  visual = new DrawingVisual();
            DrawingContext dc     = visual.RenderOpen();

            dc.DrawEllipse(fill, outline, new Point(NodePoint.X, NodePoint.Y), DefaultRadius, DefaultRadius);

            dc.Close();

            visual.SetValue(FrameworkElement.TagProperty, $"Node_{NodeId}");

            graph.Children.Add(visual);

            ++node_count;
        }
Beispiel #9
0
        public void Draw(IDictionary <string, AbstractElementVisual> drawingElements)
        {
            var caption = myPresentation.GetPropertySetFor <Caption>().Get(Owner.Id);

            Visual = new DrawingVisual();
            var dc = Visual.RenderOpen();

            var tx = new FormattedText(caption.DisplayText,
                                       CultureInfo.InvariantCulture,
                                       FlowDirection.LeftToRight,
                                       myFont,
                                       FontSize, Brushes.Black);

            const double FontPadding = BorderThickness * 2;

            var rect = GetBoundingBox(drawingElements);

            // resize rect so that cluster caption can be drawn
            rect = new Rect(
                rect.Left - FontPadding,
                rect.Top - (tx.Height + 2 * FontPadding),
                Math.Max(rect.Width, tx.Width) + 2 * FontPadding,
                rect.Height + tx.Height + 3 * FontPadding);

            // add some extra padding
            const double ExtraPadding = BorderThickness * 2;

            rect.Inflate(ExtraPadding, ExtraPadding);

            dc.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Blue, BorderThickness), rect);

            dc.DrawText(tx, new Point(rect.Left + FontPadding, rect.Top + FontPadding));

            dc.Close();

            Visual.SetValue(GraphItemProperty, Owner);
        }
Beispiel #10
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            var textformat = new FormattedText(
                string.IsNullOrEmpty(Text) ? "" : Text,
                CultureInfo.CurrentCulture,
                FlowDirection,
                Typeface, FontSize,
                Foreground);

            if (SelectionAreas == null || SelectionAreas.Count == 0)
            {
                drawingContext.DrawText(textformat, new Point(0, 0));
                return;
            }

            var chunks        = new Dictionary <FormattedText, bool>();
            var startPosition = 0;

            foreach (var selectionArea in SelectionAreas)
            {
                var selection  = Text.Substring(selectionArea.Start, selectionArea.Length);
                var textBefore = Text.Substring(startPosition, Math.Abs(selectionArea.Start - startPosition));
                startPosition = selectionArea.Start + selectionArea.Length;

                var formatTextBefore = new FormattedText(textBefore, CultureInfo.CurrentCulture, FlowDirection, Typeface, FontSize, Foreground);
                var formatTextSelect = new FormattedText(selection, CultureInfo.CurrentCulture, FlowDirection, Typeface, FontSize, StyleSelection == StyleSelection.Rectangle ? Brushes.White : Foreground);

                chunks.Add(formatTextBefore, false);
                chunks.Add(formatTextSelect, true);
            }
            var textAfter       = Text.Substring(startPosition);
            var formatTextAfter = new FormattedText(textAfter, CultureInfo.CurrentCulture, FlowDirection, Typeface, FontSize, Foreground);

            chunks.Add(formatTextAfter, false);

            var startPoint = new Point(Padding.Left, Padding.Top);

            foreach (var chunk in chunks)
            {
                if (!chunk.Value)
                {
                    drawingContext.DrawText(chunk.Key, startPoint);
                }
                else
                {
                    switch (StyleSelection)
                    {
                    case StyleSelection.Rectangle:
                        var visualRect = new DrawingVisual();
                        visualRect.SetValue(UseLayoutRoundingProperty, true);
                        visualRect.SetValue(SnapsToDevicePixelsProperty, true);
                        visualRect.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Aliased);

                        using (var context = visualRect.RenderOpen())
                        {
                            context.DrawRectangle(Brushes.Black, null,
                                                  new Rect(startPoint,
                                                           new Size(chunk.Key.WidthIncludingTrailingWhitespace,
                                                                    chunk.Key.Height)));
                        }

                        drawingContext.DrawRectangle(new VisualBrush(visualRect), null, visualRect.ContentBounds);
                        drawingContext.DrawText(chunk.Key, startPoint);
                        break;

                    case StyleSelection.Underline:
                        var startPointLine = new Point(startPoint.X,
                                                       textformat.Height - .5);

                        var endPointLine = new Point(
                            startPoint.X +
                            chunk.Key.WidthIncludingTrailingWhitespace, textformat.Height - .5);

                        var visual = new DrawingVisual();
                        visual.SetValue(UseLayoutRoundingProperty, true);
                        visual.SetValue(SnapsToDevicePixelsProperty, true);
                        visual.SetValue(RenderOptions.EdgeModeProperty, EdgeMode.Unspecified);
                        using (var context = visual.RenderOpen())
                        {
                            context.DrawLine(new Pen(Brushes.Black, 1), startPointLine, endPointLine);
                        }
                        drawingContext.DrawRectangle(new VisualBrush(visual), null, visual.ContentBounds);
                        drawingContext.DrawText(chunk.Key, startPoint);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                startPoint.X += chunk.Key.WidthIncludingTrailingWhitespace;
            }

            drawingContext.DrawRectangle(Brushes.Transparent, null, new Rect(new Point(0, 0), new Size(textformat.WidthIncludingTrailingWhitespace, textformat.Height)));
            base.OnRender(drawingContext);
        }
Beispiel #11
0
        private void DrawEdge(EdgeLayout edge)
        {
            Pen pen         = EdgeTemplate.DefaultPen;
            Pen trianglePen = new Pen()
            {
                Brush = Brushes.Black, Thickness = 3.0
            };

            if (_view.EdgeTemplate.Count > 0)
            {
                foreach (var edgeTemplate in _view.EdgeTemplate)
                {
                    if (edgeTemplate.EdgeType == null || edgeTemplate.EdgeType is System.Type type && type.IsAssignableFrom(edge.EdgeObject.GetType()))
                    {
                        //pen = edgeTemplate.Pen;
                        string objectName = (string)edge.EdgeObject;
                        if (objectName.Contains("--|>"))
                        {
                            pen = new Pen()
                            {
                                Brush = Brushes.Black, Thickness = 2.0
                            };

                            pen.DashStyle = DashStyles.Dash;
                        }
                        else if (objectName.Contains("-|>"))
                        {
                            pen = new Pen()
                            {
                                Brush = Brushes.Black, Thickness = 2.0
                            };
                        }
                        else if (objectName.Contains("-->"))
                        {
                            pen = new Pen()
                            {
                                Brush = Brushes.Black, Thickness = 2.0
                            };

                            pen.DashStyle = DashStyles.Dash;
                        }
                        else if (objectName.Contains("-"))
                        {
                            pen = new Pen()
                            {
                                Brush = Brushes.Black, Thickness = 2.0
                            };
                        }
                        break;
                    }
                }
            }
            var            visual         = new DrawingVisual();
            DrawingContext drawingContext = visual.RenderOpen();

            if (!_view.OnDrawEdge(edge, drawingContext))
            {
                var path             = new PathGeometry();
                var heightOfTriangle = pen.Thickness * 10;

                LineGeometry[] lines = calculateLinesForTriangle(edge.Splines.FirstOrDefault()[edge.Splines.FirstOrDefault().Length - 1], heightOfTriangle, edge.Splines.FirstOrDefault()[edge.Splines.FirstOrDefault().Length - 2]);

                foreach (var spline in edge.Splines)
                {
                    var pathFigure = new PathFigure();
                    pathFigure.IsClosed   = false;
                    pathFigure.StartPoint = new Point(spline[0].X, spline[0].Y);
                    for (int i = 1; i < spline.Length; i += 3)
                    {
                        var segment = new BezierSegment(new Point(spline[i].X, spline[i].Y), new Point(spline[i + 1].X, spline[i + 1].Y), new Point(spline[i + 2].X, spline[i + 2].Y), true);
                        pathFigure.Segments.Add(segment);
                    }
                    path.Figures.Add(pathFigure);
                }

                drawingContext.DrawGeometry(null, pen, path);
                if (((string)edge.EdgeObject).Contains("|>"))
                {
                    for (int i = 0; i < 3; i++)
                    {
                        drawingContext.DrawGeometry(null, trianglePen, lines[i]);
                    }
                }
                else if (((string)edge.EdgeObject).Contains("-->"))
                {
                    for (int i = 0; i < 2; i++)
                    {
                        drawingContext.DrawGeometry(null, trianglePen, lines[i]);
                    }
                }
            }
            drawingContext.Close();
            visual.SetValue(FrameworkElement.TagProperty, edge);
            _visuals.Children.Add(visual);
        }