Пример #1
0
        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);
        }
Пример #2
0
 internal bool OnDrawEdge(EdgeLayout edgeLayout, DrawingContext drawingContext)
 {
     if (DrawEdge != null)
     {
         DrawEdge(this, new DrawEdgeEventArgs(edgeLayout, drawingContext));
         return(true);
     }
     return(false);
 }
Пример #3
0
        public EdgeLayout ReadEdgeLayout(string edgeId)
        {
            int pointCount = myReader.ReadInt();
            var points     = new List <Point>();

            for (int i = 0; i < pointCount; ++i)
            {
                points.Add(ReadPoint());
            }

            var layout = new EdgeLayout(edgeId);

            layout.Points = points;

            return(layout);
        }
Пример #4
0
        /// <summary>
        /// Computes the layout of the graph using Graphviz
        /// </summary>
        /// <remarks>
        /// </remarks>
        public void Compute()
        {
            StringWriter sw = new StringWriter();

            sw.WriteLine("digraph G{");
            sw.WriteLine("rankdir={0}", this.RankDirection);

            foreach (IVertex v in this.VisitedGraph.Vertices)
            {
                if (this.vertexSizes.Count == 0)
                {
                    sw.WriteLine("{0} [shape=box];", v.ID);
                }
                else
                {
                    SizeF size = this.vertexSizes[v];
                    sw.WriteLine("{0} [shape=box, width={1}, height={2}, fixedsize=true];",
                                 v.ID,
                                 size.Width / this.DpiX,
                                 size.Height / this.DpiY
                                 );
                }
            }

            foreach (IEdge e in this.VisitedGraph.Edges)
            {
                sw.WriteLine("{0} -> {1} [label=\"{2}\"];", e.Source.ID, e.Target.ID, e.ID);
            }

            sw.WriteLine("}");

            System.Diagnostics.Debug.WriteLine(sw.ToString());

            // running graphviz
            NGraphviz.Helpers.Dot dot = new NGraphviz.Helpers.Dot(".");
            GraphLayout           gl  = dot.RunData(sw.ToString());

            // build vertex id map

            OnGraphSize(gl.Size);
            if (LayVertex != null)
            {
                foreach (IVertex v in this.VisitedGraph.Vertices)
                {
                    VertexLayout vl = (VertexLayout)gl.Vertices[v.ID.ToString()];
                    OnLayVertex(v, vl.Pos);
                }
            }

            if (LayEdge != null)
            {
                foreach (IEdge e in this.VisitedGraph.Edges)
                {
                    EdgeLayout el = (EdgeLayout)gl.Edges[e.ID.ToString()];
                    OnLayEdge(
                        e,
                        ConvertEdgePort(el.SourcePort),
                        ConvertEdgePort(el.TargetPort),
                        el.Keys);
                }
            }
        }
Пример #5
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);
        }
Пример #6
0
 public DrawEdgeEventArgs(EdgeLayout edgeLayout, DrawingContext drawingContext)
 {
     EdgeLayout     = edgeLayout;
     DrawingContext = drawingContext;
 }