Smrf.NodeXL.Visualization.Wpf.NodeXLControl.SelectMarqueedVertices C# (CSharp) Method

SelectMarqueedVertices() protected method

protected SelectMarqueedVertices ( ) : void
return void
    SelectMarqueedVertices()
    {
        AssertValid();

        Debug.Assert(m_oMarqueeBeingDragged != null);

        // Create HashSets that will contain the new selection.  HashSets are
        // used instead of lists or arrays to prevent the same vertex or edge
        // from being added twice.

        HashSet<IVertex> oVerticesToSelect;
        HashSet<IEdge> oEdgesToSelect;

        Boolean bMouseModeIsAddToSelection =
            (m_eMouseMode == MouseMode.AddToSelection);

        Boolean bMouseModeIsSubtractFromSelection =
            (m_eMouseMode == MouseMode.SubtractFromSelection);

        Boolean bControlKeyIsPressed = ControlKeyIsPressed();

        if (bMouseModeIsAddToSelection || bMouseModeIsSubtractFromSelection ||
            bControlKeyIsPressed)
        {
            // The new selection gets added to or subtracted from the old
            // selection.

            oVerticesToSelect = new HashSet<IVertex>(m_oSelectedVertices);
            oEdgesToSelect = new HashSet<IEdge>(m_oSelectedEdges);
        }
        else
        {
            // The new selection replaces the old selection.

            oVerticesToSelect = new HashSet<IVertex>();
            oEdgesToSelect = new HashSet<IEdge>();
        }

        // Loop through the vertices that intersect the marquee rectangle.

        Rect oMarqueeRectangle = m_oMarqueeBeingDragged.MarqueeRectangle;

        foreach ( IVertex oMarqueedVertex in
            m_oGraphDrawer.GetVerticesFromRectangle(oMarqueeRectangle) )
        {
            Boolean bAddToSelection = true;

            if (bControlKeyIsPressed)
            {
                // When a control key is pressed, the selected state of the
                // marqueed vertices should be inverted.

                bAddToSelection = !VertexOrEdgeIsSelected(oMarqueedVertex);
            }
            else if (bMouseModeIsSubtractFromSelection)
            {
                bAddToSelection = false;
            }

            if (bAddToSelection)
            {
                oVerticesToSelect.Add(oMarqueedVertex);
            }
            else
            {
                oVerticesToSelect.Remove(oMarqueedVertex);
            }

            if (m_bMouseAlsoSelectsIncidentEdges)
            {
                // Also loop through the vertex's incident edges.

                foreach (IEdge oEdge in oMarqueedVertex.IncidentEdges)
                {
                    if (bAddToSelection)
                    {
                        oEdgesToSelect.Add(oEdge);
                    }
                    else
                    {
                        oEdgesToSelect.Remove(oEdge);
                    }
                }
            }
        }

        SetSelected(oVerticesToSelect, oEdgesToSelect);
    }
NodeXLControl