Beispiel #1
0
        private void showAllHiddenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Grim workaround for not being able to invisible the nodes.
            foreach (KeyValuePair <GD.Node, AffectedNode> pair in _hiddenNodes)
            {
                GD.Node      node   = pair.Key;
                AffectedNode hidden = pair.Value;
                node.Attr.Color     = hidden.Color;
                node.Attr.Fillcolor = hidden.FillColor;
                node.Attr.Fontcolor = hidden.FontColor;
            }

            // We need access to the builder here :/
            if (_activeItem != null && _builders.ContainsKey(_activeItem))
            {
                BaseGraphBuilder builder = _builders[_activeItem];
                foreach (KeyValuePair <string, List <object> > pair in builder.AddedEdges)
                {
                    foreach (GD.Edge edge in pair.Value)
                    {
                        AffectedEdge hidden = edge.UserData as AffectedEdge;

                        if (hidden != null)
                        {
                            edge.Attr.Color = hidden.Color;
                            edge.UserData   = null;
                        }
                    }
                }
            }

            _hiddenNodes.Clear();
            _viewer.Refresh();
        }
Beispiel #2
0
        public void SetRefresh(BaseItem item)
        {
            BaseItem baseItem = GetActiveItem();

            if (baseItem == null)
            {
                return;
            }

            // We need access to the builder here :/
            if (baseItem != null && _builders.ContainsKey(baseItem))
            {
                BaseGraphBuilder builder = _builders[baseItem];
                if (item != null)
                {
                    string id = item.GetID();

                    // TODO - short id - added nodes do not have full ids.
                    string[] bits = id.Split('?');
                    if (bits.Length > 1)
                    {
                        id = bits[1];
                    }

                    if (builder.AddedNodes.ContainsKey(id))
                    {
                        // We know we added this node, so we do a refresh
                        ForceRefresh();
                    }
                }
            }
        }
Beispiel #3
0
        private bool UnHilite()
        {
            bool result = false;

            // Check for any to clear.
            if (_hiliteNodes.Count > 0)
            {
                foreach (KeyValuePair <GD.Node, AffectedNode> pair in _hiliteNodes)
                {
                    GD.Node      node   = pair.Key;
                    AffectedNode hidden = pair.Value;
                    node.Attr.Color     = hidden.Color;
                    node.Attr.Fillcolor = hidden.FillColor;
                    node.Attr.Fontcolor = hidden.FontColor;
                }

                // Again, we need access to the builder here :/
                if (_activeItem != null && _builders.ContainsKey(_activeItem))
                {
                    BaseGraphBuilder builder = _builders[_activeItem];
                    foreach (KeyValuePair <string, List <object> > pair in builder.AddedEdges)
                    {
                        foreach (GD.Edge edge in pair.Value)
                        {
                            AffectedEdge hidden = edge.UserData as AffectedEdge;

                            if (hidden != null)
                            {
                                edge.Attr.Color = hidden.Color;
                                edge.UserData   = null;
                            }
                        }
                    }

                    _hiliteNodes.Clear();
                    result = true;
                }
            }

            return(result);
        }
Beispiel #4
0
        private void hideNodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GD.Node node = _menuSelectedNode;
            if (node == null)
            {
                return;
            }
            if (_hiddenNodes.ContainsKey(node))
            {
                return;
            }

            // Hiding means the layout is still affected by the node,
            // but we don't have to recalculate the layout.
            // NB Setting Style.Invis doesn't work, this is a workaround.
            _hiddenNodes.Add(node, new AffectedNode(node.Attr.Color, node.Attr.Fillcolor, node.Attr.Fontcolor));

            node.Attr.Color     = GD.Color.Transparent;
            node.Attr.Fillcolor = GD.Color.Transparent;
            node.Attr.Fontcolor = GD.Color.Transparent;

            // We need access to the builder here :/
            if (_activeItem != null && _builders.ContainsKey(_activeItem))
            {
                BaseGraphBuilder builder = _builders[_activeItem];
                foreach (KeyValuePair <string, List <object> > pair in builder.AddedEdges)
                {
                    foreach (GD.Edge edge in pair.Value)
                    {
                        if (edge.Source == node.Id || edge.Target == node.Id)
                        {
                            // Abuse the userdata to hang onto the old color.
                            edge.UserData   = new AffectedEdge(edge.Attr.Color);
                            edge.Attr.Color = GD.Color.Transparent;
                        }
                    }
                }
            }
            _viewer.Refresh();
        }
Beispiel #5
0
        private bool Hilite(GD.Node node)
        {
            bool result = false;

            if (_hiliteNodes.ContainsKey(node))
            {
                return(result);
            }

            _hiliteNodes.Add(node, new AffectedNode(node.Attr.Color, node.Attr.Fillcolor, node.Attr.Fontcolor));

            Color color = _options.HiliteColor;

            GD.Color gcolor = new GD.Color(color.A, color.R, color.G, color.B);
            node.Attr.Fillcolor = gcolor;

            color  = _options.HiliteLineColor;
            gcolor = new GD.Color(color.A, color.R, color.G, color.B);

            // We need access to the builder here :/
            if (_activeItem != null && _builders.ContainsKey(_activeItem))
            {
                BaseGraphBuilder builder = _builders[_activeItem];
                foreach (KeyValuePair <string, List <object> > pair in builder.AddedEdges)
                {
                    foreach (GD.Edge edge in pair.Value)
                    {
                        if (edge.Source == node.Id || edge.Target == node.Id)
                        {
                            // Abuse the userdata to hang onto the old color.
                            edge.UserData   = new AffectedEdge(edge.Attr.Color);
                            edge.Attr.Color = gcolor;
                        }
                    }
                }
                result = true;
            }
            return(result);
        }
Beispiel #6
0
        private void thread_doWork(object sender)
        {
            try
            {
                BaseItem item = sender as BaseItem;
                _progress = 0;

                // Do our side of the work, using the builder subclass.
                BaseGraphBuilder builder = CreateBuilder();
                float            ratio   = _viewer.Width / (float)(_viewer.Height - _toolheight);
                builder.SetServiceProvider(_serviceProvider,
                                           new DThreadProgress(thread_doProgress), _sidePanel,
                                           item, GetID(), ratio, _options);

                // Hang onto this for ignores.
                if (_builders.ContainsKey(item))
                {
                    _builders[item] = builder;
                }
                else
                {
                    _builders.Add(item, builder);
                }

                try
                {
                    try
                    {
                        builder.BeforeTranslate();
                        builder.Translate();
                    }
                    finally
                    {
                        builder.AfterTranslate();
                    }
                }
                catch (ArgumentException exc)
                {
                    _logView.LogExcStr(exc, "Failed during translate");
                    _failed = true;
                }
                catch (InvalidOperationException)
                {
                    // Collection modified, fail gracefully, don't restart
                    // automatically, as it could be a slow operation.
                    _logView.LogStr("Failed during translate of:" + item.Name);
                    _failed = true;
                }

                _logView.Debug("Visible false on UI thread");
                try
                {
                    if (this.IsHandleCreated)
                    {
                        this.Invoke((DSetVisible)SetViewerVisible, new object[] { false });
                    }
                }
                catch
                {
                }

                try
                {
                    _logView.Debug("Layout on this thread");

                    // This fails a lot inside the viewer component.
                    //_viewer.SetCalculatedLayout(layout);

                    // More stable, still sometimes fails.
                    object layout = _viewer.CalculateLayout(builder.Graph);
                }
                catch (InvalidOperationException)
                {
                    _logView.LogStr("GLEE Layout error, try again with different aspect ratio");
                    _failed = true;
                }

                // This can take time itself, seconds for large graphs, and has to run on the
                // UI thread.
                _logView.Debug("Invoking SetGraph()");
                if (this.IsHandleCreated)
                {
                    this.Invoke((DSetGraph)SetGraph, new object[] { builder.Graph });
                }

                // Stop the progress timer.
                _timer.Change(Timeout.Infinite, 100);

                _logView.Debug("Thread finished");
            }
            catch (System.Threading.ThreadAbortException)
            {
                _failed = true;
            }
            catch (Exception exc)
            {
                if (_logView.LogCatchAll(exc, "Unexpected plugin error"))
                {
                    throw;
                }
                _failed = true;
            }
        }