Example #1
0
        SelectSubgraphs
        (
            NodeXLControl nodeXLControl,
            IEnumerable <IVertex> verticesToSelectSubgraphsFor,
            Decimal levels,
            Boolean selectConnectingEdges
        )
        {
            Debug.Assert(nodeXLControl != null);
            Debug.Assert(verticesToSelectSubgraphsFor != null);
            Debug.Assert(levels >= 0);
            Debug.Assert(Decimal.Remainder(levels, 0.5M) == 0M);

            // Create HashSets for all of the vertices and edges that will be
            // selected.  The key is the IVertex or IEdge.  HashSets are used to
            // prevent the same vertex or edge from being selected twice.

            HashSet <IVertex> oAllSelectedVertices = new HashSet <IVertex>();
            HashSet <IEdge>   oAllSelectedEdges    = new HashSet <IEdge>();

            foreach (IVertex oVertexToSelectSubgraphFor in
                     verticesToSelectSubgraphsFor)
            {
                // These are similar collections for the vertices and edges that
                // will be selected for this subgraph only.

                Dictionary <IVertex, Int32> oThisSubgraphSelectedVertices;
                HashSet <IEdge>             oThisSubgraphSelectedEdges;

                SubgraphCalculator.GetSubgraph(oVertexToSelectSubgraphFor, levels,
                                               selectConnectingEdges, out oThisSubgraphSelectedVertices,
                                               out oThisSubgraphSelectedEdges);

                // Consolidate the subgraph's selected vertices and edges into the
                // "all" dictionaries.

                foreach (IVertex oVertex in oThisSubgraphSelectedVertices.Keys)
                {
                    oAllSelectedVertices.Add(oVertex);
                }

                foreach (IEdge oEdge in oThisSubgraphSelectedEdges)
                {
                    oAllSelectedEdges.Add(oEdge);
                }
            }

            // Replace the selection.

            nodeXLControl.SetSelected(oAllSelectedVertices, oAllSelectedEdges);
        }
Example #2
0
        CloneVertexIntoSubgraph
        (
            IVertex oOriginalVertex,
            IGraph oSubgraph,
            Decimal decLevels
        )
        {
            Debug.Assert(oOriginalVertex != null);
            Debug.Assert(oSubgraph != null);
            Debug.Assert(decLevels >= 0);
            AssertValid();

            // Get the original vertices and edges to clone.  For the vertex
            // dictionary, the key is the IVertex and the value is the vertex's
            // level, which is the distance of the vertex from oOriginalVertex.
            // For the edge HashSet, the key is the IEdge.

            Dictionary <IVertex, Int32> oOriginalVerticesToClone;
            HashSet <IEdge>             oOriginalEdgesToClone;

            SubgraphCalculator.GetSubgraph(oOriginalVertex, decLevels, true,
                                           out oOriginalVerticesToClone, out oOriginalEdgesToClone);

            // Clone the vertices.  This dictionary maps the IDs of the original
            // vertices to their clones.

            Dictionary <Int32, IVertex> oOriginalToSubgraphVertexMapper =
                new Dictionary <Int32, IVertex>();

            IVertexCollection oSubgraphVertices = oSubgraph.Vertices;

            foreach (IVertex oOriginalVertexToClone in
                     oOriginalVerticesToClone.Keys)
            {
                IVertex oSubgraphVertex =
                    oOriginalVertexToClone.Clone(false, false);

                oSubgraphVertices.Add(oSubgraphVertex);

                oOriginalToSubgraphVertexMapper.Add(oOriginalVertexToClone.ID,
                                                    oSubgraphVertex);
            }

            // This dictionary is no longer needed.

            oOriginalVerticesToClone.Clear();
            oOriginalVerticesToClone = null;

            // Clone the edges.

            IEdgeCollection oSubgraphEdges = oSubgraph.Edges;

            foreach (IEdge oOriginalEdgeToClone in oOriginalEdgesToClone)
            {
                IVertex [] aoOriginalVertices = oOriginalEdgeToClone.Vertices;

                IVertex oSubgraphVertex1 =
                    oOriginalToSubgraphVertexMapper[aoOriginalVertices[0].ID];

                IVertex oSubgraphVertex2 =
                    oOriginalToSubgraphVertexMapper[aoOriginalVertices[1].ID];

                oSubgraphEdges.Add(oSubgraphVertex1, oSubgraphVertex2,
                                   oOriginalEdgeToClone.IsDirected);
            }

            Debug.Assert(oOriginalToSubgraphVertexMapper.ContainsKey(
                             oOriginalVertex.ID));

            return(oOriginalToSubgraphVertexMapper[oOriginalVertex.ID]);
        }