Exemple #1
0
        public Edge(IInternalEdgePresenter presenter, object edgeObject, Node source, Node target, FrameworkElement endDecoration = null, FrameworkElement centerDecoration = null, FrameworkElement startDecoration = null)
        {
            Presenter = presenter;
            EdgeObject = edgeObject;
            Source = source;
            Target = target;
            StartDecoration = startDecoration;
            EndDecoration = endDecoration;
            CenterDecoration = centerDecoration;

            #region Prepare grid
            linkGridRotateTransform = new RotateTransform();
            linkGrid = new Grid {
                ColumnDefinitions = {
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) },
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) },
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }
                },
                RenderTransformOrigin = new Point(0, 0.5d),
                RenderTransform = linkGridRotateTransform
            };
            #endregion

            #region Prepare link line
            LinkInnerLine = new Line {
                StrokeThickness = 1d,
                Stroke = Brushes.Black,
            };
            linkLine = new Border {
                Height = 20,
                Background = Brushes.Transparent,
                Child = LinkInnerLine
            };

            linkLine.Width = double.NaN;
            linkLine.VerticalAlignment = VerticalAlignment.Center;
            Grid.SetColumn(linkLine, 0);
            Grid.SetColumnSpan(linkLine, 5);
            linkGrid.Children.Add(linkLine);
            #endregion

            #region Prepare decorations
            if (StartDecoration != null) {
                StartDecoration.VerticalAlignment = VerticalAlignment.Center;
                Grid.SetColumn(StartDecoration, 0);
                linkGrid.Children.Add(StartDecoration);
            }
            if (CenterDecoration != null) {
                CenterDecoration.VerticalAlignment = VerticalAlignment.Center;
                Grid.SetColumn(CenterDecoration, 2);
                linkGrid.Children.Add(CenterDecoration);
            }
            if (EndDecoration != null) {
                EndDecoration.VerticalAlignment = VerticalAlignment.Center;
                Grid.SetColumn(EndDecoration, 4);
                linkGrid.Children.Add(EndDecoration);
            }
            #endregion

            UILink = linkGrid;
            Canvas.SetZIndex(UILink, Presenter.ZIndex);
        }
        private void UpdateDiagram()
        {
            #region Update nodes
            var oldNodes = Nodes.ToArray();
            Nodes.Clear();
            foreach (var nodeObject in GraphPresenter.GetNodes()) {
                Node node = oldNodes.FirstOrDefault(n => n.NodeObject == nodeObject);
                if (node == null) {
                    var nodePresenter = GraphPresenter.CreateNodePresenter(nodeObject);
                    node = new Node(nodePresenter, this, nodeObject);
                }
                Nodes.Add(node);
            }
            #endregion

            #region Update edges
            var oldEdges = Edges.ToArray();
            Edges.Clear();
            foreach (var edgeObject in GraphPresenter.GetEdges()) {
                Edge edge = oldEdges.FirstOrDefault(e => e.EdgeObject == edgeObject);
                if (edge == null) {
                    var edgePresenter = GraphPresenter.CreateEdgePresenter(edgeObject);
                    Node sourceNode = GetNodeByObject(edgePresenter.Source);
                    Node targetNode = GetNodeByObject(edgePresenter.Target);
                    edge = new Edge(edgePresenter, edgeObject, sourceNode, targetNode, Edge.CreateEndArrow());
                }
                Edges.Add(edge);
            }
            #endregion
        }