Beispiel #1
0
        protected void AddGraph(PocGraphInfo graphInfo)
        {
            LayoutStates.Clear();

            if (graphInfo == null)
            {
                return;
            }

            HighlightAlgorithm?.ResetHighlight();

            RemoveAllGraphElement();

            Children.Clear();


            Dictionary <int, PocVertex> vertexControlsById = new Dictionary <int, PocVertex>();

            foreach (VertexInfo <PocVertex> info in graphInfo.Verteces.OfType <VertexInfo <PocVertex> >())
            {
                AddVertexControl(info);
                vertexControlsById.Add(info.ID, info.Vertex);
            }

            int i = 0;

            foreach (EdgeInfo <PocEdge> info in graphInfo.Edges.OfType <EdgeInfo <PocEdge> >())
            {
                PocVertex source = vertexControlsById[info.SourceID];
                PocVertex target = vertexControlsById[info.TargetID];

                CreateEdgeControl(new PocEdge(i.ToString(), source, target));
                i++;
            }
        }
Beispiel #2
0
        public void HighlightTriggerEventHandler(object sender, HighlightTriggeredEventArgs args)
        {
            if (Graph == null || HighlightAlgorithm == null)
            {
                return;
            }

            if (args.OriginalSource is VertexControl)
            {
                var vc     = (VertexControl)args.OriginalSource;
                var vertex = vc.Vertex as TVertex;
                if (vertex == null || !Graph.ContainsVertex(vertex))
                {
                    return;
                }

                if (args.IsPositiveTrigger)
                {
                    HighlightAlgorithm.OnVertexHighlighting(vertex);
                }
                else
                {
                    HighlightAlgorithm.OnVertexHighlightRemoving(vertex);
                }
            }
            else if (args.OriginalSource is EdgeControl)
            {
                var   ec   = (EdgeControl)args.OriginalSource;
                TEdge edge = default(TEdge);
                try
                {
                    edge = (TEdge)ec.Edge;
                }
                catch
                {
                }

                if (Equals(edge, default(TEdge)) || !Graph.ContainsEdge(edge))
                {
                    return;
                }

                if (args.IsPositiveTrigger)
                {
                    HighlightAlgorithm.OnEdgeHighlighting(edge);
                }
                else
                {
                    HighlightAlgorithm.OnEdgeHighlightRemoving(edge);
                }
            }
        }
Beispiel #3
0
        private void OnRelayoutInduction(bool tryKeepControls)
        {
            if (HighlightAlgorithm != null)
            {
                HighlightAlgorithm.ResetHighlight();
            }

            //recreate the graph elements
            RecreateGraphElements(tryKeepControls);

            //do the layout process again
            Relayout();
        }
Beispiel #4
0
        private void DoNotificationLayout()
        {
            lock (_notificationSyncRoot)
            {
                _lastNotificationTimestamp = DateTime.Now;
            }

            if (Worker != null)
            {
                return;
            }

            Worker         = new BackgroundWorker();
            Worker.DoWork += (s, e) =>
            {
                var w = (BackgroundWorker)s;
                lock (_notificationSyncRoot)
                {
                    while ((DateTime.Now - _lastNotificationTimestamp) < _notificationLayoutDelay)
                    {
                        Thread.Sleep(_notificationLayoutDelay);
                        if (w.CancellationPending)
                        {
                            break;
                        }
                    }
                }
            };
            Worker.RunWorkerCompleted += (s, e) =>
            {
                Worker = null;
                OnMutation();
                ContinueLayout();
                if (HighlightAlgorithm != null)
                {
                    HighlightAlgorithm.ResetHighlight();
                }
            };
            Worker.RunWorkerAsync();
        }