protected VertexControl GetOrCreateVertexControl([NotNull] TVertex vertex)
        {
            VertexControl vertexControl = GetVertexControl(vertex);

            if (vertexControl is null)
            {
                return(CreateVertexControl(vertex));
            }
            return(vertexControl);
        }
        protected virtual VertexControl CreateVertexControl([NotNull] TVertex vertex)
        {
            var compoundGraph = Graph as ICompoundGraph <TVertex, TEdge>;

            VertexControl vertexControl;

            if (IsCompoundMode && compoundGraph != null && compoundGraph.IsCompoundVertex(vertex))
            {
                var compoundVertexControl = new CompoundVertexControl
                {
                    Vertex      = vertex,
                    DataContext = vertex,
                };
                vertexControl = compoundVertexControl;
            }
            else
            {
                // Create the Control of the vertex
                vertexControl = new VertexControl
                {
                    Vertex      = vertex,
                    DataContext = vertex,
                };
            }

            VerticesControls[vertex] = vertexControl;
            vertexControl.RootCanvas = this;

            if (IsCompoundMode && compoundGraph != null && compoundGraph.IsChildVertex(vertex))
            {
                TVertex parent = compoundGraph.GetParent(vertex);

                Debug.Assert(parent != null, "Vertex considered as child one has no parent.");

                var parentControl = GetOrCreateVertexControl(parent) as CompoundVertexControl;

                Debug.Assert(parentControl != null);

                parentControl.Vertices.Add(vertexControl);
            }
            else
            {
                // Add the presenter to the GraphLayout
                Children.Add(vertexControl);
            }

            // Measure & Arrange
            vertexControl.InvalidateMeasure();
            SetHighlightProperties(vertex, vertexControl);
            RunCreationTransition(vertexControl);

            return(vertexControl);
        }
        /// <summary>
        /// Initializes the position of the given <paramref name="vertex"/>.
        /// </summary>
        /// <param name="vertex">Graph vertex.</param>
        protected virtual void InitializePosition([NotNull] TVertex vertex)
        {
            VertexControl vertexControl = VerticesControls[vertex];

            // Initialize position
            if (Graph.ContainsVertex(vertex) &&
                Graph.Degree(vertex) > 0 &&
                TryComputePosition(vertex, out Point position))
            {
                SetX(vertexControl, position.X);
                SetY(vertexControl, position.Y);
            }
        }
        protected virtual void CreateVertexControl(TVertex vertex)
        {
            VertexControl presenter;
            var           compoundGraph = Graph as ICompoundGraph <TVertex, TEdge>;

            if (IsCompoundMode && compoundGraph != null && compoundGraph.IsCompoundVertex(vertex))
            {
                var compoundPresenter = new CompoundVertexControl
                {
                    Vertex      = vertex,
                    DataContext = vertex,
                };
                compoundPresenter.Expanded  += CompoundVertexControl_ExpandedOrCollapsed;
                compoundPresenter.Collapsed += CompoundVertexControl_ExpandedOrCollapsed;
                presenter = compoundPresenter;
            }
            else
            {
                // Create the Control of the vertex
                presenter = new VertexControl
                {
                    Vertex      = vertex,
                    DataContext = vertex,
                };
            }

            //var presenter = _vertexPool.GetObject();
            //presenter.Vertex = vertex;
            _vertexControls[vertex] = presenter;
            presenter.RootCanvas    = this;

            if (IsCompoundMode && compoundGraph != null && compoundGraph.IsChildVertex(vertex))
            {
                var parent        = compoundGraph.GetParent(vertex);
                var parentControl = GetOrCreateVertexControl(parent) as CompoundVertexControl;

                Debug.Assert(parentControl != null);

                parentControl.Vertices.Add(presenter);
            }
            else
            {
                //add the presenter to the GraphLayout
                Children.Add(presenter);
            }

            //Measuring & Arrange
            presenter.InvalidateMeasure();
            SetHighlightProperties(vertex, presenter);
            RunCreationTransition(presenter);
        }
Beispiel #5
0
        private void SetHighlightProperties([NotNull] TVertex vertex, [NotNull] VertexControl vertexControl)
        {
            Debug.Assert(vertex != null);
            Debug.Assert(vertexControl != null);

            if (IsHighlightedVertex(vertex, out object highlightInfo))
            {
                GraphElementBehaviour.SetIsHighlighted(vertexControl, true);
                GraphElementBehaviour.SetHighlightInfo(vertexControl, highlightInfo);
            }

            if (IsSemiHighlightedVertex(vertex, out object semiHighlightInfo))
            {
                GraphElementBehaviour.SetIsSemiHighlighted(vertexControl, true);
                GraphElementBehaviour.SetSemiHighlightInfo(vertexControl, semiHighlightInfo);
            }
        }
        private void SetHighlightProperties(TVertex vertex, VertexControl presenter)
        {
            object highlightInfo;

            if (IsHighlightedVertex(vertex, out highlightInfo))
            {
                GraphElementBehaviour.SetIsHighlighted(presenter, true);
                GraphElementBehaviour.SetHighlightInfo(presenter, highlightInfo);
            }

            object semiHighlightInfo;

            if (IsSemiHighlightedVertex(vertex, out semiHighlightInfo))
            {
                GraphElementBehaviour.SetIsSemiHighlighted(presenter, true);
                GraphElementBehaviour.SetSemiHighlightInfo(presenter, semiHighlightInfo);
            }
        }