/// <summary>
        /// Called by the various node creation callbacks to create a node in the resulting graph view
        /// that corresponds to the provided <paramref name="layoutNode"/>.
        /// </summary>
        /// <remarks>
        /// If a model node is provided, the ports of the original node will be copied to the created view node.
        /// Also, a clone of the original node style will be used as the style of the created node.
        /// </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="layoutNode">The node of the layout graph that should be copied</param>
        /// <param name="modelNode">The node of the original input graph that corresponds to the <paramref name="layoutNode"/> (may be <see langword="null"/>)</param>
        /// <param name="isReferenceNode"></param>
        /// <param name="nodeDefaults"></param>
        /// <returns>the created node</returns>
        /// <seealso cref="CreateConnectorNode"/>
        /// <seealso cref="CreateNormalNode"/>
        /// <seealso cref="CreateGroupNode"/>
        /// <seealso cref="CreateProxyNode"/>
        /// <seealso cref="CreateProxyReferenceNode"/>
        protected INode CreateNodeCore(LayoutGraph pageLayoutGraph, IGraph pageView, Node layoutNode, INode modelNode, bool isReferenceNode, INodeDefaults nodeDefaults)
        {
            // get the layout from the layout graph
            INodeLayout nodeLayout = pageLayoutGraph.GetLayout(layoutNode);
            // get the style from the node defaults or the model node (or the default style if none is provided)
            INodeStyle style = (INodeStyle)(nodeDefaults.Style != NullNodeStyle
                                         ? nodeDefaults.GetStyleInstance()
                                         : (modelNode != null
                                              ? modelNode.Style.Clone()
                                              : pageView.NodeDefaults.Style.Clone()));
            var tag = modelNode != null ? modelNode.Tag : null;
            // create the copied node
            INode viewNode = pageView.CreateNode(new RectD(nodeLayout.X, nodeLayout.Y, nodeLayout.Width, nodeLayout.Height), style, tag);

            // copy the ports of the model node
            if (modelNode != null)
            {
                CopyPorts(pageView, layoutNode, viewNode, modelNode);
            }

            viewToLayoutNode[viewNode] = layoutNode;
            IMapper <INode, NodeData> referencingMapper = pageView.MapperRegistry.GetMapper <INode, NodeData>(MapperKeyNodeData);
            NodeData data = new NodeData {
                IsReferenceNode = isReferenceNode
            };

            referencingMapper[viewNode] = data;

            return(viewNode);
        }
Exemple #2
0
        protected void PaintNode(Graphics g, LayoutGraph graph, Node node)
        {
            INodeLayout nl   = graph.GetLayout(node);
            RectangleF  rect = RectangleF.FromLTRB((float)nl.X, (float)nl.Y, (float)(nl.X + nl.Width),
                                                   (float)(nl.Y + nl.Height));
            Region r = new Region(rect);

            g.FillRegion(nodeFillBrush, r);
            points[0] = new PointF(rect.X, rect.Y);
            points[1] = new PointF(rect.X + rect.Width, rect.Y);
            points[2] = new PointF(rect.X + rect.Width, rect.Y + rect.Height);
            points[3] = new PointF(rect.X, rect.Y + rect.Height);
            g.DrawPolygon(nodeBorderPen, points);
            string text = node.Index.ToString();
            SizeF  size = g.MeasureString(text, labelFont);

            g.DrawString(text, labelFont, labelBrush, rect.X + rect.Width * 0.5f - size.Width * 0.5f,
                         rect.Y + rect.Height * 0.5f - size.Height * 0.5f);
        }
        /// <summary>
        /// Creates an animation that morphs the layout of all <see cref="ITable"/>s in the graph.
        /// </summary>
        /// <seealso cref="TableAnimation"/>
        /// <seealso cref="ConfigureTableNodeLayout"/>
        protected virtual IAnimation CreateTableAnimations()
        {
            var anims = new List <IAnimation>();

            foreach (var node in graph.Nodes)
            {
                var table = node.Lookup <ITable>();
                if (table != null)
                {
                    INodeLayout nodeLayout = layoutGraph.GetLayout(layoutGraph.GetCopiedNode(node));

                    var columnLayout = TableLayoutConfigurator.GetColumnLayout(table,
                                                                               new RectD(nodeLayout.X, nodeLayout.Y, nodeLayout.Width, nodeLayout.Height));
                    var rowLayout = TableLayoutConfigurator.GetRowLayout(table,
                                                                         new RectD(nodeLayout.X, nodeLayout.Y, nodeLayout.Width, nodeLayout.Height));
                    anims.Add(new TableAnimation(table, columnLayout, rowLayout));
                }
            }
            return(anims.CreateParallelAnimation());
        }
            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);
                }
            }