ReadEdgeTable
(
ListObject oEdgeTable,
ReadWorkbookContext oReadWorkbookContext,
IGraph oGraph
)
{
Debug.Assert(oEdgeTable != null);
Debug.Assert(oReadWorkbookContext != null);
Debug.Assert(oGraph != null);
AssertValid();
Boolean bReadAllEdgeAndVertexColumns =
oReadWorkbookContext.ReadAllEdgeAndVertexColumns;
if (oReadWorkbookContext.FillIDColumns)
{
FillIDColumn(oEdgeTable);
}
Dictionary<String, IVertex> oVertexNameDictionary =
oReadWorkbookContext.VertexNameDictionary;
EdgeVisibilityConverter oEdgeVisibilityConverter =
new EdgeVisibilityConverter();
Boolean bGraphIsDirected =
(oGraph.Directedness == GraphDirectedness.Directed);
ExcelTableReader oExcelTableReader = new ExcelTableReader(oEdgeTable);
IVertexCollection oVertices = oGraph.Vertices;
IEdgeCollection oEdges = oGraph.Edges;
HashSet<String> oColumnNamesToExclude = new HashSet<String>(
new String[] {
EdgeTableColumnNames.Vertex1Name,
EdgeTableColumnNames.Vertex2Name
} );
foreach ( ExcelTableReader.ExcelTableRow oRow in
oExcelTableReader.GetRows() )
{
// Get the names of the edge's vertices.
String sVertex1Name, sVertex2Name;
Boolean bVertex1IsEmpty = !oRow.TryGetNonEmptyStringFromCell(
EdgeTableColumnNames.Vertex1Name, out sVertex1Name);
Boolean bVertex2IsEmpty = !oRow.TryGetNonEmptyStringFromCell(
EdgeTableColumnNames.Vertex2Name, out sVertex2Name);
if (bVertex1IsEmpty && bVertex2IsEmpty)
{
// Skip empty rows.
continue;
}
if (bVertex1IsEmpty || bVertex2IsEmpty)
{
// A half-empty row is an error.
OnHalfEmptyEdgeRow(oRow, bVertex1IsEmpty);
}
// Assume a default visibility.
Visibility eVisibility = Visibility.Show;
String sVisibility;
if (
oRow.TryGetNonEmptyStringFromCell(
CommonTableColumnNames.Visibility, out sVisibility)
&&
!oEdgeVisibilityConverter.TryWorkbookToGraph(
sVisibility, out eVisibility)
)
{
OnInvalidVisibility(oRow);
}
if (eVisibility == Visibility.Skip)
{
// Skip the edge an continue to the next edge.
continue;
}
// Create the specified vertices or retrieve them from the
// dictionary.
IVertex oVertex1 = VertexNameToVertex(
sVertex1Name, oVertices, oVertexNameDictionary);
IVertex oVertex2 = VertexNameToVertex(
sVertex2Name, oVertices, oVertexNameDictionary);
// Add an edge connecting the vertices.
IEdge oEdge = oEdges.Add(oVertex1, oVertex2, bGraphIsDirected);
// If ReadWorkbookContext.FillIDColumns is true, add the edge to
// the edge row ID dictionary and set the edge's Tag to the row ID.
oReadWorkbookContext.AddToRowIDDictionary(oRow, oEdge, true);
if (bReadAllEdgeAndVertexColumns)
{
// All columns except the vertex names should be read and
// stored as metadata on the edge.
ReadAllColumns(oExcelTableReader, oRow, oEdge,
oColumnNamesToExclude);
continue;
}
if (eVisibility == Visibility.Hide)
{
// Hide the edge and continue to the next edge.
oEdge.SetValue(ReservedMetadataKeys.Visibility,
VisibilityKeyValue.Hidden);
continue;
}
// Alpha.
Boolean bAlphaIsZero = ReadAlpha(oRow, oEdge);
if (bAlphaIsZero)
{
continue;
}
// Color.
ReadColor(oRow, EdgeTableColumnNames.Color, oEdge,
ReservedMetadataKeys.PerColor,
oReadWorkbookContext.ColorConverter2);
// Width.
ReadWidth(oRow, oReadWorkbookContext.EdgeWidthConverter, oEdge);
// Style.
ReadStyle(oRow, oReadWorkbookContext.EdgeStyleConverter, oEdge);
// Label.
if (oReadWorkbookContext.ReadEdgeLabels)
{
ReadCellAndSetMetadata(oRow, EdgeTableColumnNames.Label, oEdge,
ReservedMetadataKeys.PerEdgeLabel);
ReadColor(oRow, EdgeTableColumnNames.LabelTextColor, oEdge,
ReservedMetadataKeys.PerEdgeLabelTextColor,
oReadWorkbookContext.ColorConverter2);
ReadLabelFontSize(oRow, oReadWorkbookContext.FontSizeConverter,
oEdge);
}
// Weight.
if (oReadWorkbookContext.ReadEdgeWeights)
{
ReadEdgeWeight(oRow, oEdge);
}
}
if (bReadAllEdgeAndVertexColumns)
{
// Store the edge column names on the graph.
oGraph.SetValue( ReservedMetadataKeys.AllEdgeMetadataKeys,
FilterColumnNames(oExcelTableReader, oColumnNamesToExclude) );
}
}