Exemple #1
0
        protected void PaintEdge(Graphics g, LayoutGraph graph, Edge e)
        {
            IEdgeLayout el = graph.GetLayout(e);
            YPoint      sp = graph.GetSourcePointAbs(e);
            YPoint      tp = graph.GetTargetPointAbs(e);

            PointF[] points = new PointF[el.PointCount() + 2];
            points[0] = new PointF((float)sp.X, (float)sp.Y);
            points[el.PointCount() + 1] = new PointF((float)tp.X, (float)tp.Y);
            for (int i = 0; i < el.PointCount(); i++)
            {
                YPoint p = el.GetPoint(i);
                points[i + 1] = new PointF((float)p.X, (float)p.Y);
            }
            g.DrawLines(edgePen, points);
        }
        /// <summary>
        /// Called by the various edge creation callbacks to create an edge in the resulting graph view
        /// that corresponds to the provided <paramref name="layoutEdge"/>.
        /// </summary>
        /// <remarks>
        /// If a model edge is provided, the edge will be created between the copies of the corresponding
        /// source/target ports.
        /// </remarks>
        ///<param name="pageLayoutGraph">The layout graph representing the current page.</param>
        ///<param name="pageView">The <see cref="IGraph"/> that is built to show the multi-page layout in a graph canvas.</param>
        ///<param name="layoutEdge">The edge of the layout graph that should be copied.</param>
        ///<param name="modelEdge">The edge of the original input graph that corresponds to the <paramref name="layoutEdge"/> (may be <see langword="null"/>).</param>
        ///<param name="edgeDefaults"></param>
        ///<returns>The created edge</returns>
        /// <seealso cref="CreateConnectorEdge"/>
        /// <seealso cref="CreateNormalEdge"/>
        /// <seealso cref="CreateProxyEdge"/>
        /// <seealso cref="CreateProxyReferenceEdge"/>
        protected IEdge CreateEdgeCore(LayoutGraph pageLayoutGraph, IGraph pageView, Edge layoutEdge, IEdge modelEdge, IEdgeDefaults edgeDefaults)
        {
            IEdge viewEdge;

            if (modelEdge != null)
            {
                // if the edge has a model edge: create the copied edge between
                // the copies of its source and target ports
                IPort      modelSourcePort = modelEdge.SourcePort;
                IPort      modelTargetPort = modelEdge.TargetPort;
                IPort      viewSourcePort  = GetViewPort(modelSourcePort);
                IPort      viewTargetPort  = GetViewPort(modelTargetPort);
                IEdgeStyle style           = (IEdgeStyle)(edgeDefaults.Style != NullEdgeStyle ?
                                                          edgeDefaults.GetStyleInstance() :
                                                          modelEdge.Style.Clone());
                viewEdge = pageView.CreateEdge(viewSourcePort, viewTargetPort, style, modelEdge.Tag);
            }
            else
            {
                // otherwise create it between the copies of its source and target nodes
                INode viewSource = GetViewNode(layoutEdge.Source);
                INode viewTarget = GetViewNode(layoutEdge.Target);
                viewEdge = pageView.CreateEdge(viewSource, viewTarget);
            }

            // adjust the port location
            YPoint newSourcePortLocation = pageLayoutGraph.GetSourcePointAbs(layoutEdge);
            YPoint newTargetPortLocation = pageLayoutGraph.GetTargetPointAbs(layoutEdge);

            pageView.SetPortLocation(viewEdge.SourcePort, newSourcePortLocation.ToPointD());
            pageView.SetPortLocation(viewEdge.TargetPort, newTargetPortLocation.ToPointD());

            // and copy the bends
            IEdgeLayout edgeLayout = pageLayoutGraph.GetLayout(layoutEdge);

            for (int i = 0; i < edgeLayout.PointCount(); i++)
            {
                YPoint bendLocation = edgeLayout.GetPoint(i);
                pageView.AddBend(viewEdge, new PointD(bendLocation.X, bendLocation.Y), i);
            }

            return(viewEdge);
        }
            public GraphCanvas(LayoutGraph graph)
            {
                this.RenderTransform = new TranslateTransform(_padding, _padding);
                var grouping = new GroupingSupport(graph);

                // Add all edges
                foreach (var edge in graph.Edges)
                {
                    IEdgeLayout el = graph.GetLayout(edge);
                    var         l  = new Polyline();
                    l.Stroke = Brushes.Black;
                    l.Points.Add(new Point(graph.GetSourcePointAbs(edge).X, graph.GetSourcePointAbs(edge).Y));
                    for (int i = 0; i < el.PointCount(); i++)
                    {
                        Point p = new Point(el.GetPoint(i).X, el.GetPoint(i).Y);
                        l.Points.Add(p);
                    }
                    l.Points.Add(new Point(graph.GetTargetPointAbs(edge).X, graph.GetTargetPointAbs(edge).Y));
                    this.Children.Add(l);

                    // edge labels
                    var edgeLabelLayout = graph.GetLabelLayout(edge);
                    foreach (var labelLayout in edgeLabelLayout)
                    {
                        var orientedRectangle = labelLayout.LabelModel.GetLabelPlacement(
                            labelLayout.BoundingBox,
                            graph.GetLayout(edge),
                            graph.GetLayout(edge.Source),
                            graph.GetLayout(edge.Target),
                            labelLayout.ModelParameter);
                        this.Children.Add(GetPolygon(orientedRectangle));
                    }
                }

                // add all nodes
                foreach (var node in graph.Nodes)
                {
                    INodeLayout nl    = graph.GetLayout(node);
                    Color       color = grouping.IsGroupNode(node) ? Color.FromArgb(60, 255, 60, 0) : Color.FromArgb(255, 255, 255, 0);


                    var rect = new Rectangle();
                    this.Children.Add(rect);
                    rect.Stroke = new SolidColorBrush()
                    {
                        Color = Colors.Black
                    };
                    rect.Fill = new SolidColorBrush()
                    {
                        Color = color
                    };
                    rect.Width  = nl.Width;
                    rect.Height = nl.Height;
                    Canvas.SetTop(rect, nl.Y);
                    Canvas.SetLeft(rect, nl.X);

                    // display the node index
                    var text = new TextBlock()
                    {
                        Text = String.Empty + node.Index,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        VerticalAlignment   = VerticalAlignment.Center
                    };

                    this.Children.Add(text);
                    text.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                    Canvas.SetTop(text, nl.Y + nl.Height / 2 - text.DesiredSize.Height / 2);
                    Canvas.SetLeft(text, nl.X + nl.Width / 2 - text.DesiredSize.Width / 2);
                }
            }
Exemple #4
0
        public override void ApplyLayout(LayoutGraph graph)
        {
            ApplyLayoutCore(graph);

            foreach (Node n in graph.Nodes)
            {
                foreach (Edge e in n.OutEdges)
                {
                    bool        lastSegmentOverlap = false;
                    IEdgeLayout er = graph.GetLayout(e);
                    if (er.PointCount() > 0)
                    {
                        // last bend point
                        YPoint bendPoint = er.GetPoint(er.PointCount() - 1);

                        IEnumerator <Edge> ecc = n.OutEdges.GetEnumerator();
                        loop : while (ecc.MoveNext())
                        {
                            Edge eccEdge = ecc.Current;
                            if (eccEdge != e)
                            {
                                YPointPath path = graph.GetPath(eccEdge);
                                for (ILineSegmentCursor lc = path.LineSegments(); lc.Ok; lc.Next())
                                {
                                    LineSegment seg = lc.LineSegment;
                                    if (seg.Contains(bendPoint))
                                    {
                                        lastSegmentOverlap = true;
                                        goto loop;
                                    }
                                }
                            }
                        }
                    }


                    YList points = graph.GetPointList(e);
                    for (ListCell c = points.FirstCell; c != null; c = c.Succ())
                    {
                        YPoint p = (YPoint)c.Info;
                        if (c.Succ() == null && !lastSegmentOverlap)
                        {
                            break;
                        }

                        YPoint p0 = (YPoint)(c.Pred() == null ? graph.GetSourcePointAbs(e) : c.Pred().Info);
                        YPoint p2;
                        if (Math.Abs(p0.X - p.X) < 0.01)
                        {
                            p2 = new YPoint(p.X, p.Y - 0.001);
                        }
                        else
                        {
                            p2 = new YPoint(p.X - 0.001, p.Y);
                        }

                        points.InsertBefore(p2, c);
                    }
                    graph.SetPoints(e, points);
                }
            }
        }