SetSelectionByRowIDs
(
ICollection<Int32> oEdgeRowIDs,
ICollection<Int32> oVertexRowIDs
)
{
Debug.Assert( (oEdgeRowIDs == null) != (oVertexRowIDs == null) );
AssertValid();
if (oNodeXLControl.IsLayingOutGraph || !this.NonEmptyWorkbookRead)
{
return;
}
Boolean bAutoSelect = ( new GeneralUserSettings() ).AutoSelect;
// The row IDs get converted below to dictionaries of IEdge and IVertex
// objects. Dictionaries are used to prevent duplicates. The key is
// the IEdge.ID or IVertex.ID (NOT the row IDs) and the value is the
// IEdge or IVertex.
Dictionary<Int32, IEdge> oEdgesToSelect =
new Dictionary<Int32, IEdge>();
Dictionary<Int32, IVertex> oVerticesToSelect =
new Dictionary<Int32, IVertex>();
if (bAutoSelect)
{
// In AutoSelect mode, the selection in one or the other worksheet
// determines the entire selection state. For example, selecting a
// vertex in the vertices worksheet selects the vertex and its
// incident edges, but ignores any other edges that may have
// already been selected in the edges worksheet.
}
else
{
// In manual mode, when a vertex is selected in the vertex
// worksheet, the selection in the vertex worksheet determines
// which vertices are selected, but the selected edges are left
// alone. Similiarly, when an edge is selected in the edge
// worksheet, the selection in the edge worksheet determines which
// edges are selected, but the selected vertices are left alone.
if (oVertexRowIDs != null)
{
oEdgesToSelect =
NodeXLControlUtil.GetSelectedEdgesAsDictionary(
oNodeXLControl);
}
else if (oEdgeRowIDs != null)
{
oVerticesToSelect =
NodeXLControlUtil.GetSelectedVerticesAsDictionary(
oNodeXLControl);
}
else
{
Debug.Assert(false);
}
}
if (oEdgeRowIDs != null)
{
foreach (Int32 iEdgeRowID in oEdgeRowIDs)
{
IIdentityProvider oEdge;
if ( m_oEdgeRowIDDictionary.TryGetValue(iEdgeRowID,
out oEdge) )
{
Debug.Assert(oEdge is IEdge);
IEdge oEdgeAsEdge = (IEdge)oEdge;
oEdgesToSelect[oEdgeAsEdge.ID] = oEdgeAsEdge;
if (bAutoSelect)
{
IVertex [] aoAdjacentVertices = oEdgeAsEdge.Vertices;
oVerticesToSelect[aoAdjacentVertices[0].ID]
= aoAdjacentVertices[0];
oVerticesToSelect[aoAdjacentVertices[1].ID]
= aoAdjacentVertices[1];
}
}
}
}
else
{
foreach (Int32 iVertexRowID in oVertexRowIDs)
{
IIdentityProvider oVertex;
if ( m_oVertexRowIDDictionary.TryGetValue(iVertexRowID,
out oVertex) )
{
Debug.Assert(oVertex is IVertex);
IVertex oVertexAsVertex = (IVertex)oVertex;
oVerticesToSelect[oVertexAsVertex.ID] = oVertexAsVertex;
if (bAutoSelect)
{
foreach (IEdge oIncidentEdge in
oVertexAsVertex.IncidentEdges)
{
oEdgesToSelect[oIncidentEdge.ID] = oIncidentEdge;
}
}
}
}
}
oNodeXLControl.SetSelected(oVerticesToSelect.Values,
oEdgesToSelect.Values);
}