SetUp()
 {
     m_oEdgeVisibilityConverter = new EdgeVisibilityConverter();
 }
 public void TearDown()
 {
     m_oEdgeVisibilityConverter = null;
 }
 //*************************************************************************
 //  Constructor: EdgeVisibilityConverterTest()
 //
 /// <summary>
 /// Initializes a new instance of the <see
 /// cref="EdgeVisibilityConverterTest" /> class.
 /// </summary>
 //*************************************************************************
 public EdgeVisibilityConverterTest()
 {
     m_oEdgeVisibilityConverter = null;
 }
    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) );
        }
    }
Exemplo n.º 5
0
 SetUp()
 {
     m_oEdgeVisibilityConverter = new EdgeVisibilityConverter();
 }
Exemplo n.º 6
0
    ThisWorkbook_AttributesEditedInGraph
    (
        Object sender,
        AttributesEditedEventArgs e
    )
    {
        Debug.Assert(e != null);
        AssertValid();

        // The key is the row ID stored in the table's ID column and the value
        // is the one-based row number relative to the worksheet.

        Dictionary<Int32, Int32> oRowIDDictionary;

        if (
            e.EditedEdgeAttributes == null
            ||
            !m_oSheets1And2Helper.TableExists
            ||
            !m_oSheets1And2Helper.TryGetAllRowIDs(out oRowIDDictionary)
            )
        {
            return;
        }

        Microsoft.Office.Interop.Excel.ListObject oEdgeTable =
            Edges.InnerObject;

        Globals.ThisWorkbook.ShowWaitCursor = true;

        // Get the columns that might need to be updated.  These columns are
        // not required.

        Microsoft.Office.Interop.Excel.Range oColorColumnData,
            oWidthColumnData, oStyleColumnData, oAlphaColumnData,
            oVisibilityColumnData, oLabelColumnData,
            oLabelTextColorColumnData, oLabelFontSizeColumnData;

        Object [,] aoColorValues = null;
        Object [,] aoWidthValues = null;
        Object [,] aoStyleValues = null;
        Object [,] aoAlphaValues = null;
        Object [,] aoVisibilityValues = null;
        Object [,] aoLabelValues = null;
        Object [,] aoLabelTextColorValues = null;
        Object [,] aoLabelFontSizeValues = null;

        ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
            EdgeTableColumnNames.Color, out oColorColumnData,
            out aoColorValues);

        ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
            EdgeTableColumnNames.Width, out oWidthColumnData,
            out aoWidthValues);

        ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
            EdgeTableColumnNames.Style, out oStyleColumnData,
            out aoStyleValues);

        ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
            CommonTableColumnNames.Alpha, out oAlphaColumnData,
            out aoAlphaValues);

        ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
            CommonTableColumnNames.Visibility, out oVisibilityColumnData,
            out aoVisibilityValues);

        ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
            EdgeTableColumnNames.Label, out oLabelColumnData,
            out aoLabelValues);

        ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
            EdgeTableColumnNames.LabelTextColor, out oLabelTextColorColumnData,
            out aoLabelTextColorValues);

        ExcelTableUtil.TryGetTableColumnDataAndValues(oEdgeTable,
            EdgeTableColumnNames.LabelFontSize, out oLabelFontSizeColumnData,
            out aoLabelFontSizeValues);

        ColorConverter2 oColorConverter2 = new ColorConverter2();
        EdgeStyleConverter oEdgeStyleConverter = new EdgeStyleConverter();

        EdgeVisibilityConverter oEdgeVisibilityConverter =
            new EdgeVisibilityConverter();

        // Loop through the IDs of the edges whose attributes were edited
        // in the graph.

        EditedEdgeAttributes oEditedEdgeAttributes = e.EditedEdgeAttributes;

        foreach (Int32 iID in e.EdgeIDs)
        {
            // Look for the row that contains the ID.

            Int32 iRowOneBased;

            if ( !oRowIDDictionary.TryGetValue(iID, out iRowOneBased) )
            {
                continue;
            }

            iRowOneBased -= oEdgeTable.Range.Row;

            if (oEditedEdgeAttributes.Color.HasValue && aoColorValues != null)
            {
                aoColorValues[iRowOneBased, 1] =
                    oColorConverter2.GraphToWorkbook(
                        oEditedEdgeAttributes.Color.Value);
            }

            if (oEditedEdgeAttributes.Width.HasValue && aoWidthValues != null)
            {
                aoWidthValues[iRowOneBased, 1] =
                    oEditedEdgeAttributes.Width.Value.ToString();
            }

            if (oEditedEdgeAttributes.Style.HasValue && aoStyleValues != null)
            {
                aoStyleValues[iRowOneBased, 1] =
                    oEdgeStyleConverter.GraphToWorkbook(
                        oEditedEdgeAttributes.Style.Value);
            }

            if (oEditedEdgeAttributes.Alpha.HasValue && aoAlphaValues != null)
            {
                aoAlphaValues[iRowOneBased, 1] =
                    oEditedEdgeAttributes.Alpha.Value.ToString();
            }

            if (oEditedEdgeAttributes.Visibility.HasValue &&
                aoVisibilityValues != null)
            {
                aoVisibilityValues[iRowOneBased, 1] =
                    oEdgeVisibilityConverter.GraphToWorkbook(
                        oEditedEdgeAttributes.Visibility.Value);
            }

            if ( !String.IsNullOrEmpty(oEditedEdgeAttributes.Label) )
            {
                aoLabelValues[iRowOneBased, 1] = oEditedEdgeAttributes.Label;
            }

            if (oEditedEdgeAttributes.LabelTextColor.HasValue &&
                aoLabelTextColorValues != null)
            {
                aoLabelTextColorValues[iRowOneBased, 1] =
                    oColorConverter2.GraphToWorkbook(
                        oEditedEdgeAttributes.LabelTextColor.Value);
            }

            if (oEditedEdgeAttributes.LabelFontSize.HasValue &&
                aoLabelFontSizeValues != null)
            {
                aoLabelFontSizeValues[iRowOneBased, 1] =
                    oEditedEdgeAttributes.LabelFontSize.Value.ToString();
            }
        }

        // Activate this worksheet first, because writing to an inactive
        // worksheet causes problems with the selection in Excel.

        ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer =
            m_oSheets1And2Helper.GetExcelActiveWorksheetRestorer();

        ExcelActiveWorksheetState oExcelActiveWorksheetState =
            oExcelActiveWorksheetRestorer.ActivateWorksheet(this.InnerObject);

        try
        {
            m_oSheets1And2Helper.SetColumnDataValues(
                oColorColumnData, aoColorValues,
                oWidthColumnData, aoWidthValues,
                oStyleColumnData, aoStyleValues,
                oAlphaColumnData, aoAlphaValues,
                oVisibilityColumnData, aoVisibilityValues,
                oLabelColumnData, aoLabelValues,
                oLabelTextColorColumnData, aoLabelTextColorValues,
                oLabelFontSizeColumnData, aoLabelFontSizeValues
                );
        }
        finally
        {
            oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
        }

        Globals.ThisWorkbook.ShowWaitCursor = false;
    }