Exemple #1
0
        //*************************************************************************
        //  Constructor: ReadWorkbookContext()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadWorkbookContext" />
        /// class.
        /// </summary>
        //*************************************************************************

        public ReadWorkbookContext()
        {
            m_bIgnoreVertexLocations   = true;
            m_bFillIDColumns           = false;
            m_bPopulateVertexWorksheet = false;
            m_bReadEdgeWeights         = false;
            m_bReadGroups                  = false;
            m_bSaveGroupVertices           = false;
            m_bReadVertexLabels            = false;
            m_bReadEdgeLabels              = false;
            m_bReadVertexImages            = false;
            m_oDefaultVertexImageSize      = new Nullable <Single>();
            m_eDefaultVertexShape          = VertexShape.Disk;
            m_bReadAllEdgeAndVertexColumns = false;
            m_oGraphRectangle              = Rectangle.FromLTRB(0, 0, 100, 100);
            m_oColorConverter2             = new ColorConverter2();
            m_oBooleanConverter            = new BooleanConverter();
            m_oEdgeWidthConverter          = new EdgeWidthConverter();
            m_oEdgeStyleConverter          = new EdgeStyleConverter();
            m_oVertexRadiusConverter       = new VertexRadiusConverter();

            m_oVertexLocationConverter =
                new VertexLocationConverter(m_oGraphRectangle);

            m_oVertexNameDictionary  = new Dictionary <String, IVertex>();
            m_oEdgeRowIDDictionary   = new Dictionary <Int32, IIdentityProvider>();
            m_oVertexRowIDDictionary = new Dictionary <Int32, IIdentityProvider>();

            AssertValid();
        }
Exemple #2
0
        SetVertexAttributesForAllGroups
        (
            ListObject oGroupTable
        )
        {
            Debug.Assert(oGroupTable != null);

            Range oVertexColorRange, oVertexShapeRange;

            Object [,] aoVertexColorValues, aoVertexShapeValues;

            if (
                !ExcelUtil.TryGetTableColumnDataAndValues(oGroupTable,
                                                          GroupTableColumnNames.VertexShape, out oVertexShapeRange,
                                                          out aoVertexShapeValues)
                ||
                !ExcelUtil.TryGetTableColumnDataAndValues(oGroupTable,
                                                          GroupTableColumnNames.VertexColor, out oVertexColorRange,
                                                          out aoVertexColorValues)
                )
            {
                return;
            }

            Int32 iGroups = aoVertexShapeValues.GetUpperBound(0);

            Debug.Assert(aoVertexColorValues.GetUpperBound(0) == iGroups);

            ColorConverter2 oColorConverter2 = new ColorConverter2();

            VertexShapeConverter oVertexShapeConverter =
                new VertexShapeConverter();

            for (Int32 i = 0; i < iGroups; i++)
            {
                Color       oColor;
                VertexShape eShape;

                GetVertexAttributes(i, iGroups, out oColor, out eShape);

                // Write the color in a format that is understood by
                // ColorConverter2.WorkbookToGraph(), which is what
                // WorksheetReaderBase uses.

                aoVertexColorValues[i + 1, 1] =
                    oColorConverter2.GraphToWorkbook(oColor);

                aoVertexShapeValues[i + 1, 1] =
                    oVertexShapeConverter.GraphToWorkbook(eShape);
            }

            oVertexColorRange.set_Value(Missing.Value, aoVertexColorValues);
            oVertexShapeRange.set_Value(Missing.Value, aoVertexShapeValues);
        }
Exemple #3
0
        TryGetColor
        (
            ExcelTableReader.ExcelTableRow oRow,
            String sColumnName,
            ColorConverter2 oColorConverter2,
            out Color oColor
        )
        {
            Debug.Assert(oRow != null);
            Debug.Assert(!String.IsNullOrEmpty(sColumnName));
            Debug.Assert(oColorConverter2 != null);
            AssertValid();

            oColor = Color.Empty;

            String sColor;

            if (!oRow.TryGetNonEmptyStringFromCell(sColumnName, out sColor))
            {
                return(false);
            }

            if (!oColorConverter2.TryWorkbookToGraph(sColor, out oColor))
            {
                Range oInvalidCell = oRow.GetRangeForCell(sColumnName);

                OnWorkbookFormatError(String.Format(

                                          "The cell {0} contains an unrecognized color.  Right-click the"
                                          + " cell and select Select Color on the right-click menu."
                                          ,
                                          ExcelUtil.GetRangeAddress(oInvalidCell)
                                          ),

                                      oInvalidCell
                                      );
            }

            return(true);
        }
Exemple #4
0
        ReadColor
        (
            ExcelTableReader.ExcelTableRow oRow,
            String sColumnName,
            IMetadataProvider oEdgeOrVertex,
            String sColorKey,
            ColorConverter2 oColorConverter2
        )
        {
            Debug.Assert(oRow != null);
            Debug.Assert(!String.IsNullOrEmpty(sColumnName));
            Debug.Assert(oEdgeOrVertex != null);
            Debug.Assert(!String.IsNullOrEmpty(sColorKey));
            Debug.Assert(oColorConverter2 != null);
            AssertValid();

            Color oColor;

            if (TryGetColor(oRow, sColumnName, oColorConverter2, out oColor))
            {
                oEdgeOrVertex.SetValue(sColorKey, oColor);
            }
        }
        //*************************************************************************
        //  Method: AutoFillByVertexCategory()
        //
        /// <summary>
        /// Assigns attributes based on a vertex category column.
        /// </summary>
        ///
        /// <param name="oWorkbook">
        /// The workbook to autofill.
        /// </param>
        ///
        /// <param name="oEdgeTable">
        /// The edge table.
        /// </param>
        ///
        /// <param name="oVertexTable">
        /// The vertex table.
        /// </param>
        ///
        /// <param name="sVertexCategoryColumnName">
        /// The name of the vertex table column containing vertex categories.
        /// </param>
        ///
        /// <param name="bShowVertexLabels">
        /// true if vertex labels should be shown.
        /// </param>
        ///
        /// <param name="sVertexLabelColumnName">
        /// The name of the vertex table column containing vertex labels.  Used
        /// only if <paramref name="bShowVertexLabels" /> is true.
        /// </param>
        //*************************************************************************
        private static void AutoFillByVertexCategory(
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Microsoft.Office.Interop.Excel.ListObject oEdgeTable,
            Microsoft.Office.Interop.Excel.ListObject oVertexTable,
            String sVertexCategoryColumnName,
            Boolean bShowVertexLabels,
            String sVertexLabelColumnName
            )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oEdgeTable != null);
            Debug.Assert(oVertexTable != null);
            Debug.Assert( !String.IsNullOrEmpty(sVertexCategoryColumnName) );

            Debug.Assert( !bShowVertexLabels ||
            !String.IsNullOrEmpty(sVertexLabelColumnName) );

            Range oVisibleCategoryRange = null;
            Range oVisibleShapeRange = null;
            Range oVisibleColorRange = null;
            Range oVisibleRadiusRange = null;;

            if (
            !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                sVertexCategoryColumnName, out oVisibleCategoryRange)
            ||
            !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                VertexTableColumnNames.Shape, out oVisibleShapeRange)
            ||
            !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                VertexTableColumnNames.Color, out oVisibleColorRange)
            ||
            !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                VertexTableColumnNames.Radius, out oVisibleRadiusRange)
            )
            {
            ErrorUtil.OnMissingColumn();
            }

            // Loop through the visible areas to create a dictionary of categories.
            // The key is a unique category name and the value is a scheme index.
            // If the category column contains three unique categories, for
            // example, the dictionary entries will look like this:
            //
            // Category A, 0
            // Category B, 1
            // Category C, 2

            Dictionary<String, Int32> oCategoryDictionary =
            new Dictionary<String, Int32>();

            Areas oCategoryAreas = oVisibleCategoryRange.Areas;
            Int32 iAreas = oCategoryAreas.Count;
            Int32 iSchemeIndex = 0;

            for (Int32 iArea = 1; iArea <= iAreas; iArea++)
            {
            Object [,] aoCategoryValues = ExcelUtil.GetRangeValues(
                oCategoryAreas[iArea] );

            Int32 iRows = aoCategoryValues.GetUpperBound(0);
            String sCategory;

            for (Int32 iRow = 1; iRow <= iRows; iRow++)
            {
                if ( ExcelUtil.TryGetNonEmptyStringFromCell(aoCategoryValues,
                    iRow, 1, out sCategory) )
                {
                    if ( !oCategoryDictionary.ContainsKey(sCategory) )
                    {
                        oCategoryDictionary[sCategory] = iSchemeIndex;
                        iSchemeIndex++;
                    }
                }
            }
            }

            // Scheme index that will be used for vertices that have an empty
            // category cell.

            Int32 SchemeIndexForNoCategory = iSchemeIndex;

            Areas oShapeAreas = oVisibleShapeRange.Areas;
            Areas oColorAreas = oVisibleColorRange.Areas;
            Areas oRadiusAreas = oVisibleRadiusRange.Areas;

            Debug.Assert(oShapeAreas.Count == iAreas);
            Debug.Assert(oColorAreas.Count == iAreas);
            Debug.Assert(oRadiusAreas.Count == iAreas);

            ColorConverter2 oColorConverter2 = new ColorConverter2();

            VertexShapeConverter oVertexShapeConverter =
            new VertexShapeConverter();

            // Loop through the visible areas again, this time to fill in the
            // vertex shape, color, and radius columns.

            for (Int32 iArea = 1; iArea <= iAreas; iArea++)
            {
            Object [,] aoCategoryValues = ExcelUtil.GetRangeValues(
                oCategoryAreas[iArea] );

            Range oShapeArea = oShapeAreas[iArea];
            Range oColorArea = oColorAreas[iArea];
            Range oRadiusArea = oRadiusAreas[iArea];

            Object [,] aoShapeValues = ExcelUtil.GetRangeValues(oShapeArea);
            Object [,] aoColorValues = ExcelUtil.GetRangeValues(oColorArea);
            Object [,] aoRadiusValues = ExcelUtil.GetRangeValues(oRadiusArea);

            Int32 iRows = aoCategoryValues.GetUpperBound(0);

            Debug.Assert(aoShapeValues.GetUpperBound(0) == iRows);
            Debug.Assert(aoColorValues.GetUpperBound(0) == iRows);
            Debug.Assert(aoRadiusValues.GetUpperBound(0) == iRows);

            String sCategory;

            for (Int32 iRow = 1; iRow <= iRows; iRow++)
            {
                if ( ExcelUtil.TryGetNonEmptyStringFromCell(aoCategoryValues,
                    iRow, 1, out sCategory) )
                {
                    iSchemeIndex = oCategoryDictionary[sCategory];
                }
                else
                {
                    iSchemeIndex = SchemeIndexForNoCategory;
                }

                VertexShape eShape;
                Color oColor;
                Single fRadius;

                GetVertexCategoryScheme(iSchemeIndex, out eShape, out oColor,
                    out fRadius);

                aoShapeValues[iRow, 1] =
                    oVertexShapeConverter.GraphToWorkbook(eShape);

                // Write the color in a format that is understood by
                // ColorConverter.ConvertFromString(), which is what
                // WorksheetReaderBase uses.

                aoColorValues[iRow, 1] =
                    oColorConverter2.GraphToWorkbook(oColor);

                aoRadiusValues[iRow, 1] = fRadius;
            }

            oShapeArea.set_Value(Missing.Value, aoShapeValues);
            oColorArea.set_Value(Missing.Value, aoColorValues);
            oRadiusArea.set_Value(Missing.Value, aoRadiusValues);
            }

            // Fill in other columns with constants.

            FillColumnsWithConstants(

            oVertexTable, CommonTableColumnNames.Alpha,
                AlphaConverter.MaximumAlphaWorkbook,

            oEdgeTable, EdgeTableColumnNames.Color,
                oColorConverter2.GraphToWorkbook(
                    Color.FromArgb(179, 179, 179) ),

            oEdgeTable, EdgeTableColumnNames.Width, 1.0F,

            oEdgeTable, CommonTableColumnNames.Alpha,
                AlphaConverter.MaximumAlphaWorkbook
            );

            // Save the results.

            SaveVertexCategoryResults(oWorkbook, sVertexCategoryColumnName,
            oCategoryDictionary);
        }
Exemple #6
0
        AutoFillByVertexCategory
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            Microsoft.Office.Interop.Excel.ListObject oEdgeTable,
            Microsoft.Office.Interop.Excel.ListObject oVertexTable,
            String sVertexCategoryColumnName,
            Boolean bShowVertexLabels,
            String sVertexLabelColumnName
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oEdgeTable != null);
            Debug.Assert(oVertexTable != null);
            Debug.Assert(!String.IsNullOrEmpty(sVertexCategoryColumnName));

            Debug.Assert(!bShowVertexLabels ||
                         !String.IsNullOrEmpty(sVertexLabelColumnName));

            Range oVisibleCategoryRange = null;
            Range oVisibleShapeRange    = null;
            Range oVisibleColorRange    = null;
            Range oVisibleRadiusRange   = null;;

            if (
                !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                                                        sVertexCategoryColumnName, out oVisibleCategoryRange)
                ||
                !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                                                        VertexTableColumnNames.Shape, out oVisibleShapeRange)
                ||
                !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                                                        VertexTableColumnNames.Color, out oVisibleColorRange)
                ||
                !ExcelUtil.TryGetVisibleTableColumnData(oVertexTable,
                                                        VertexTableColumnNames.Radius, out oVisibleRadiusRange)
                )
            {
                ErrorUtil.OnMissingColumn();
            }

            // Loop through the visible areas to create a dictionary of categories.
            // The key is a unique category name and the value is a scheme index.
            // If the category column contains three unique categories, for
            // example, the dictionary entries will look like this:
            //
            // Category A, 0
            // Category B, 1
            // Category C, 2

            Dictionary <String, Int32> oCategoryDictionary =
                new Dictionary <String, Int32>();

            Areas oCategoryAreas = oVisibleCategoryRange.Areas;
            Int32 iAreas         = oCategoryAreas.Count;
            Int32 iSchemeIndex   = 0;

            for (Int32 iArea = 1; iArea <= iAreas; iArea++)
            {
                Object [,] aoCategoryValues = ExcelUtil.GetRangeValues(
                    oCategoryAreas[iArea]);

                Int32  iRows = aoCategoryValues.GetUpperBound(0);
                String sCategory;

                for (Int32 iRow = 1; iRow <= iRows; iRow++)
                {
                    if (ExcelUtil.TryGetNonEmptyStringFromCell(aoCategoryValues,
                                                               iRow, 1, out sCategory))
                    {
                        if (!oCategoryDictionary.ContainsKey(sCategory))
                        {
                            oCategoryDictionary[sCategory] = iSchemeIndex;
                            iSchemeIndex++;
                        }
                    }
                }
            }

            // Scheme index that will be used for vertices that have an empty
            // category cell.

            Int32 SchemeIndexForNoCategory = iSchemeIndex;

            Areas oShapeAreas  = oVisibleShapeRange.Areas;
            Areas oColorAreas  = oVisibleColorRange.Areas;
            Areas oRadiusAreas = oVisibleRadiusRange.Areas;

            Debug.Assert(oShapeAreas.Count == iAreas);
            Debug.Assert(oColorAreas.Count == iAreas);
            Debug.Assert(oRadiusAreas.Count == iAreas);

            ColorConverter2 oColorConverter2 = new ColorConverter2();

            VertexShapeConverter oVertexShapeConverter =
                new VertexShapeConverter();

            // Loop through the visible areas again, this time to fill in the
            // vertex shape, color, and radius columns.

            for (Int32 iArea = 1; iArea <= iAreas; iArea++)
            {
                Object [,] aoCategoryValues = ExcelUtil.GetRangeValues(
                    oCategoryAreas[iArea]);

                Range oShapeArea  = oShapeAreas[iArea];
                Range oColorArea  = oColorAreas[iArea];
                Range oRadiusArea = oRadiusAreas[iArea];

                Object [,] aoShapeValues  = ExcelUtil.GetRangeValues(oShapeArea);
                Object [,] aoColorValues  = ExcelUtil.GetRangeValues(oColorArea);
                Object [,] aoRadiusValues = ExcelUtil.GetRangeValues(oRadiusArea);

                Int32 iRows = aoCategoryValues.GetUpperBound(0);

                Debug.Assert(aoShapeValues.GetUpperBound(0) == iRows);
                Debug.Assert(aoColorValues.GetUpperBound(0) == iRows);
                Debug.Assert(aoRadiusValues.GetUpperBound(0) == iRows);

                String sCategory;

                for (Int32 iRow = 1; iRow <= iRows; iRow++)
                {
                    if (ExcelUtil.TryGetNonEmptyStringFromCell(aoCategoryValues,
                                                               iRow, 1, out sCategory))
                    {
                        iSchemeIndex = oCategoryDictionary[sCategory];
                    }
                    else
                    {
                        iSchemeIndex = SchemeIndexForNoCategory;
                    }

                    VertexShape eShape;
                    Color       oColor;
                    Single      fRadius;

                    GetVertexCategoryScheme(iSchemeIndex, out eShape, out oColor,
                                            out fRadius);

                    aoShapeValues[iRow, 1] =
                        oVertexShapeConverter.GraphToWorkbook(eShape);

                    // Write the color in a format that is understood by
                    // ColorConverter.ConvertFromString(), which is what
                    // WorksheetReaderBase uses.

                    aoColorValues[iRow, 1] =
                        oColorConverter2.GraphToWorkbook(oColor);

                    aoRadiusValues[iRow, 1] = fRadius;
                }

                oShapeArea.set_Value(Missing.Value, aoShapeValues);
                oColorArea.set_Value(Missing.Value, aoColorValues);
                oRadiusArea.set_Value(Missing.Value, aoRadiusValues);
            }

            // Fill in other columns with constants.

            FillColumnsWithConstants(

                oVertexTable, CommonTableColumnNames.Alpha,
                AlphaConverter.MaximumAlphaWorkbook,

                oEdgeTable, EdgeTableColumnNames.Color,
                oColorConverter2.GraphToWorkbook(
                    Color.FromArgb(179, 179, 179)),

                oEdgeTable, EdgeTableColumnNames.Width, 1.0F,

                oEdgeTable, CommonTableColumnNames.Alpha,
                AlphaConverter.MaximumAlphaWorkbook
                );

            // Save the results.

            SaveVertexCategoryResults(oWorkbook, sVertexCategoryColumnName,
                                      oCategoryDictionary);
        }
 public void TearDown()
 {
     m_oColorConverter2 = null;
 }
 public void SetUp()
 {
     m_oColorConverter2 = new ColorConverter2();
 }
 //*************************************************************************
 //  Constructor: ColorConverter2Test()
 //
 /// <summary>
 /// Initializes a new instance of the <see cref="ColorConverter2Test" />
 /// class.
 /// </summary>
 //*************************************************************************
 public ColorConverter2Test()
 {
     m_oColorConverter2 = null;
 }
Exemple #10
0
        //*************************************************************************
        //  Method: SetVertexAttributesForAllGroups()
        //
        /// <summary>
        /// Sets the vertex attributes for all the groups in the group table.
        /// </summary>
        ///
        /// <param name="oGroupTable">
        /// The group table.
        /// </param>
        //*************************************************************************
        private static void SetVertexAttributesForAllGroups(
            ListObject oGroupTable
            )
        {
            Debug.Assert(oGroupTable != null);

            Range oVertexColorRange, oVertexShapeRange;
            Object [,] aoVertexColorValues, aoVertexShapeValues;

            if (
            !ExcelUtil.TryGetTableColumnDataAndValues(oGroupTable,
                GroupTableColumnNames.VertexShape, out oVertexShapeRange,
                out aoVertexShapeValues)
            ||
            !ExcelUtil.TryGetTableColumnDataAndValues(oGroupTable,
                GroupTableColumnNames.VertexColor, out oVertexColorRange,
                out aoVertexColorValues)
            )
            {
            return;
            }

            Int32 iGroups = aoVertexShapeValues.GetUpperBound(0);
            Debug.Assert(aoVertexColorValues.GetUpperBound(0) == iGroups);

            ColorConverter2 oColorConverter2 = new ColorConverter2();

            VertexShapeConverter oVertexShapeConverter =
            new VertexShapeConverter();

            for (Int32 i = 0; i < iGroups; i++)
            {
            Color oColor;
            VertexShape eShape;

            GetVertexAttributes(i, iGroups, out oColor, out eShape);

            // Write the color in a format that is understood by
            // ColorConverter2.WorkbookToGraph(), which is what
            // WorksheetReaderBase uses.

            aoVertexColorValues[i + 1, 1] =
                oColorConverter2.GraphToWorkbook(oColor);

            aoVertexShapeValues[i + 1, 1] =
                oVertexShapeConverter.GraphToWorkbook(eShape);
            }

            oVertexColorRange.set_Value(Missing.Value, aoVertexColorValues);
            oVertexShapeRange.set_Value(Missing.Value, aoVertexShapeValues);
        }
Exemple #11
0
        //*************************************************************************
        //  Method: OnVertexAttributesEditedInGraph()
        //
        /// <summary>
        /// Handles the VertexAttributesEditedInGraph event on ThisWorkbook.
        /// </summary>
        ///
        /// <param name="e">
        /// Standard event argument.
        /// </param>
        //*************************************************************************
        private void OnVertexAttributesEditedInGraph(
            VertexAttributesEditedEventArgs e
            )
        {
            Debug.Assert(e != null);
            AssertValid();

            Microsoft.Office.Interop.Excel.ListObject oVertexTable =
            Vertices.InnerObject;

            // Get a dictionary containing the ID of each row in the table.

            Dictionary<Int32, Int32> oRowIDDictionary;

            if ( !m_oSheets1And2Helper.TryGetAllRowIDs(out oRowIDDictionary) )
            {
            // Nothing can be done without the IDs.

            return;
            }

            Globals.ThisWorkbook.ShowWaitCursor = true;

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

            Microsoft.Office.Interop.Excel.Range oColorColumnData,
            oShapeColumnData, oRadiusColumnData, oAlphaColumnData,
            oVisibilityColumnData, oLabelPositionColumnData, oLockedColumnData,
            oMarkedColumnData;

            Object [,] aoColorValues = null;
            Object [,] aoShapeValues = null;
            Object [,] aoRadiusValues = null;
            Object [,] aoAlphaValues = null;
            Object [,] aoVisibilityValues = null;
            Object [,] aoLabelPositionValues = null;
            Object [,] aoLockedValues = null;
            Object [,] aoMarkedValues = null;

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
            VertexTableColumnNames.Color, out oColorColumnData,
            out aoColorValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
            VertexTableColumnNames.Shape, out oShapeColumnData,
            out aoShapeValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
            VertexTableColumnNames.Radius, out oRadiusColumnData,
            out aoRadiusValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
            CommonTableColumnNames.Alpha, out oAlphaColumnData,
            out aoAlphaValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
            CommonTableColumnNames.Visibility, out oVisibilityColumnData,
            out aoVisibilityValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
            VertexTableColumnNames.LabelPosition, out oLabelPositionColumnData,
            out aoLabelPositionValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
            VertexTableColumnNames.Locked, out oLockedColumnData,
            out aoLockedValues);

            if ( TryGetMarkedColumnData(out oMarkedColumnData) )
            {
            aoMarkedValues = ExcelUtil.GetRangeValues(oMarkedColumnData);
            }

            ColorConverter2 oColorConverter2 = new ColorConverter2();

            VertexShapeConverter oVertexShapeConverter =
            new VertexShapeConverter();

            VertexVisibilityConverter oVertexVisibilityConverter =
            new VertexVisibilityConverter();

            VertexLabelPositionConverter oVertexLabelPositionConverter =
            new VertexLabelPositionConverter();

            BooleanConverter oBooleanConverter = new BooleanConverter();

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

            EditedVertexAttributes oEditedVertexAttributes =
            e.EditedVertexAttributes;

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

            Int32 iRowOneBased;

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

            iRowOneBased -= oVertexTable.Range.Row;

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

            if (oEditedVertexAttributes.Shape.HasValue &&
                aoShapeValues != null)
            {
                aoShapeValues[iRowOneBased, 1] =
                    oVertexShapeConverter.GraphToWorkbook(
                        oEditedVertexAttributes.Shape.Value);
            }

            if (oEditedVertexAttributes.Radius.HasValue &&
                aoRadiusValues != null)
            {
                aoRadiusValues[iRowOneBased, 1] =
                    oEditedVertexAttributes.Radius.Value.ToString();
            }

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

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

            if (oEditedVertexAttributes.LabelPosition.HasValue &&
                aoLabelPositionValues != null)
            {
                aoLabelPositionValues[iRowOneBased, 1] =
                    oVertexLabelPositionConverter.GraphToWorkbook(
                        oEditedVertexAttributes.LabelPosition.Value);
            }

            if (oEditedVertexAttributes.Locked.HasValue &&
                aoLockedValues != null)
            {
                aoLockedValues[iRowOneBased, 1] =
                    oBooleanConverter.GraphToWorkbook(
                        oEditedVertexAttributes.Locked.Value);
            }

            if (oEditedVertexAttributes.Marked.HasValue &&
                aoMarkedValues != null)
            {
                aoMarkedValues[iRowOneBased, 1] =
                    oBooleanConverter.GraphToWorkbook(
                        oEditedVertexAttributes.Marked.Value);
            }
            }

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

            ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer =
            GetExcelActiveWorksheetRestorer();

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

            try
            {
            if (aoColorValues != null)
            {
                oColorColumnData.set_Value(Missing.Value, aoColorValues);
            }

            if (aoShapeValues != null)
            {
                oShapeColumnData.set_Value(Missing.Value, aoShapeValues);
            }

            if (aoRadiusValues != null)
            {
                oRadiusColumnData.set_Value(Missing.Value, aoRadiusValues);
            }

            if (aoAlphaValues != null)
            {
                oAlphaColumnData.set_Value(Missing.Value, aoAlphaValues);
            }

            if (aoVisibilityValues != null)
            {
                oVisibilityColumnData.set_Value(Missing.Value,
                    aoVisibilityValues);
            }

            if (aoLabelPositionValues != null)
            {
                oLabelPositionColumnData.set_Value(Missing.Value,
                    aoLabelPositionValues);
            }

            if (aoLockedValues != null)
            {
                oLockedColumnData.set_Value(Missing.Value, aoLockedValues);
            }

            if (aoMarkedValues != null)
            {
                oMarkedColumnData.set_Value(Missing.Value, aoMarkedValues);
            }
            }
            finally
            {
            oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }

            Globals.ThisWorkbook.ShowWaitCursor = false;
        }
Exemple #12
0
        OnVertexAttributesEditedInGraph
        (
            VertexAttributesEditedEventArgs e
        )
        {
            Debug.Assert(e != null);
            AssertValid();

            Microsoft.Office.Interop.Excel.ListObject oVertexTable =
                Vertices.InnerObject;

            // Get a dictionary containing the ID of each row in the table.

            Dictionary <Int32, Int32> oRowIDDictionary;

            if (!m_oSheets1And2Helper.TryGetAllRowIDs(out oRowIDDictionary))
            {
                // Nothing can be done without the IDs.

                return;
            }

            Globals.ThisWorkbook.ShowWaitCursor = true;

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

            Microsoft.Office.Interop.Excel.Range oColorColumnData,
                                                 oShapeColumnData, oRadiusColumnData, oAlphaColumnData,
                                                 oVisibilityColumnData, oLabelPositionColumnData, oLockedColumnData,
                                                 oMarkedColumnData;

            Object [,] aoColorValues         = null;
            Object [,] aoShapeValues         = null;
            Object [,] aoRadiusValues        = null;
            Object [,] aoAlphaValues         = null;
            Object [,] aoVisibilityValues    = null;
            Object [,] aoLabelPositionValues = null;
            Object [,] aoLockedValues        = null;
            Object [,] aoMarkedValues        = null;

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.Color, out oColorColumnData,
                                                     out aoColorValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.Shape, out oShapeColumnData,
                                                     out aoShapeValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.Radius, out oRadiusColumnData,
                                                     out aoRadiusValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     CommonTableColumnNames.Alpha, out oAlphaColumnData,
                                                     out aoAlphaValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     CommonTableColumnNames.Visibility, out oVisibilityColumnData,
                                                     out aoVisibilityValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.LabelPosition, out oLabelPositionColumnData,
                                                     out aoLabelPositionValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.Locked, out oLockedColumnData,
                                                     out aoLockedValues);

            if (TryGetMarkedColumnData(out oMarkedColumnData))
            {
                aoMarkedValues = ExcelUtil.GetRangeValues(oMarkedColumnData);
            }

            ColorConverter2 oColorConverter2 = new ColorConverter2();

            VertexShapeConverter oVertexShapeConverter =
                new VertexShapeConverter();

            VertexVisibilityConverter oVertexVisibilityConverter =
                new VertexVisibilityConverter();

            VertexLabelPositionConverter oVertexLabelPositionConverter =
                new VertexLabelPositionConverter();

            BooleanConverter oBooleanConverter = new BooleanConverter();

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

            EditedVertexAttributes oEditedVertexAttributes =
                e.EditedVertexAttributes;

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

                Int32 iRowOneBased;

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

                iRowOneBased -= oVertexTable.Range.Row;

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

                if (oEditedVertexAttributes.Shape.HasValue &&
                    aoShapeValues != null)
                {
                    aoShapeValues[iRowOneBased, 1] =
                        oVertexShapeConverter.GraphToWorkbook(
                            oEditedVertexAttributes.Shape.Value);
                }

                if (oEditedVertexAttributes.Radius.HasValue &&
                    aoRadiusValues != null)
                {
                    aoRadiusValues[iRowOneBased, 1] =
                        oEditedVertexAttributes.Radius.Value.ToString();
                }

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

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

                if (oEditedVertexAttributes.LabelPosition.HasValue &&
                    aoLabelPositionValues != null)
                {
                    aoLabelPositionValues[iRowOneBased, 1] =
                        oVertexLabelPositionConverter.GraphToWorkbook(
                            oEditedVertexAttributes.LabelPosition.Value);
                }

                if (oEditedVertexAttributes.Locked.HasValue &&
                    aoLockedValues != null)
                {
                    aoLockedValues[iRowOneBased, 1] =
                        oBooleanConverter.GraphToWorkbook(
                            oEditedVertexAttributes.Locked.Value);
                }

                if (oEditedVertexAttributes.Marked.HasValue &&
                    aoMarkedValues != null)
                {
                    aoMarkedValues[iRowOneBased, 1] =
                        oBooleanConverter.GraphToWorkbook(
                            oEditedVertexAttributes.Marked.Value);
                }
            }

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

            ExcelActiveWorksheetRestorer oExcelActiveWorksheetRestorer =
                GetExcelActiveWorksheetRestorer();

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

            try
            {
                if (aoColorValues != null)
                {
                    oColorColumnData.set_Value(Missing.Value, aoColorValues);
                }

                if (aoShapeValues != null)
                {
                    oShapeColumnData.set_Value(Missing.Value, aoShapeValues);
                }

                if (aoRadiusValues != null)
                {
                    oRadiusColumnData.set_Value(Missing.Value, aoRadiusValues);
                }

                if (aoAlphaValues != null)
                {
                    oAlphaColumnData.set_Value(Missing.Value, aoAlphaValues);
                }

                if (aoVisibilityValues != null)
                {
                    oVisibilityColumnData.set_Value(Missing.Value,
                                                    aoVisibilityValues);
                }

                if (aoLabelPositionValues != null)
                {
                    oLabelPositionColumnData.set_Value(Missing.Value,
                                                       aoLabelPositionValues);
                }

                if (aoLockedValues != null)
                {
                    oLockedColumnData.set_Value(Missing.Value, aoLockedValues);
                }

                if (aoMarkedValues != null)
                {
                    oMarkedColumnData.set_Value(Missing.Value, aoMarkedValues);
                }
            }
            finally
            {
                oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }

            Globals.ThisWorkbook.ShowWaitCursor = false;
        }
        //*************************************************************************
        //  Method: TryGetColor()
        //
        /// <summary>
        /// Attempts to get a color from a worksheet cell.
        /// </summary>
        ///
        /// <param name="oRow">
        /// Row to check.
        /// </param>
        ///
        /// <param name="sColumnName">
        /// Name of the column to check.
        /// </param>
        ///
        /// <param name="oColorConverter2">
        /// Object for converting the color from a string to a Color.
        /// </param>
        ///
        /// <param name="oColor">
        /// Where the color gets stored if true is returned.
        /// </param>
        ///
        /// <returns>
        /// true if the specified cell contains a valid color.
        /// </returns>
        ///
        /// <remarks>
        /// If the specified cell is empty, false is returned.  If the cell
        /// contains a valid color, the color gets stored at <paramref
        /// name="oColor" /> and true is returned.  If the cell contains an invalid
        /// color, a <see cref="WorkbookFormatException" /> is thrown.
        /// </remarks>
        //*************************************************************************
        protected Boolean TryGetColor(
            ExcelTableReader.ExcelTableRow oRow,
            String sColumnName,
            ColorConverter2 oColorConverter2,
            out Color oColor
            )
        {
            Debug.Assert(oRow != null);
            Debug.Assert( !String.IsNullOrEmpty(sColumnName) );
            Debug.Assert(oColorConverter2 != null);
            AssertValid();

            oColor = Color.Empty;

            String sColor;

            if ( !oRow.TryGetNonEmptyStringFromCell(sColumnName, out sColor) )
            {
            return (false);
            }

            if ( !oColorConverter2.TryWorkbookToGraph(sColor, out oColor) )
            {
            Range oInvalidCell = oRow.GetRangeForCell(sColumnName);

            OnWorkbookFormatError( String.Format(

                "The cell {0} contains an unrecognized color.  Right-click the"
                + " cell and select Select Color on the right-click menu."
                ,
                ExcelUtil.GetRangeAddress(oInvalidCell)
                ),

                oInvalidCell
            );
            }

            return (true);
        }
        //*************************************************************************
        //  Method: ReadColor()
        //
        /// <summary>
        /// If a color has been specified for an edge or vertex, sets the edge's
        /// or vertex's color.
        /// </summary>
        ///
        /// <param name="oRow">
        /// Row to check.
        /// </param>
        ///
        /// <param name="sColumnName">
        /// Name of the column to check.
        /// </param>
        ///
        /// <param name="oEdgeOrVertex">
        /// Edge or vertex to set the color on.
        /// </param>
        ///
        /// <param name="sColorKey">
        /// Name of the metadata key that stores the color on the edge or vertex.
        /// </param>
        ///
        /// <param name="oColorConverter2">
        /// Object for converting the color from a string to a Color.
        /// </param>
        //*************************************************************************
        protected void ReadColor(
            ExcelTableReader.ExcelTableRow oRow,
            String sColumnName,
            IMetadataProvider oEdgeOrVertex,
            String sColorKey,
            ColorConverter2 oColorConverter2
            )
        {
            Debug.Assert(oRow != null);
            Debug.Assert( !String.IsNullOrEmpty(sColumnName) );
            Debug.Assert(oEdgeOrVertex != null);
            Debug.Assert( !String.IsNullOrEmpty(sColorKey) );
            Debug.Assert(oColorConverter2 != null);
            AssertValid();

            Color oColor;

            if ( TryGetColor(oRow, sColumnName, oColorConverter2, out oColor) )
            {
            oEdgeOrVertex.SetValue(sColorKey, oColor);
            }
        }
        ReadClusterTable
        (
            ListObject oClusterTable,
            ReadWorkbookContext oReadWorkbookContext
        )
        {
            Debug.Assert(oClusterTable != null);
            Debug.Assert(oReadWorkbookContext != null);
            AssertValid();

            Dictionary <String, ClusterInformation> oClusterNameDictionary =
                new Dictionary <String, ClusterInformation>();

            ColorConverter2 oColorConverter2 =
                oReadWorkbookContext.ColorConverter2;

            ExcelTableReader oExcelTableReader =
                new ExcelTableReader(oClusterTable);

            foreach (ExcelTableReader.ExcelTableRow oRow in
                     oExcelTableReader.GetRows())
            {
                // Get the cluster information.

                String      sClusterName;
                Color       oVertexColor;
                VertexShape eVertexShape;

                if (
                    !oRow.TryGetNonEmptyStringFromCell(
                        ClusterTableColumnNames.Name, out sClusterName)
                    ||
                    !TryGetColor(oRow, ClusterTableColumnNames.VertexColor,
                                 oColorConverter2, out oVertexColor)
                    ||
                    !TryGetVertexShape(oRow, ClusterTableColumnNames.VertexShape,
                                       out eVertexShape)
                    )
                {
                    continue;
                }

                // Add the cluster information to the dictionary.

                ClusterInformation oClusterInformation =
                    new ClusterInformation();

                oClusterInformation.VertexColor = oVertexColor;
                oClusterInformation.VertexShape = eVertexShape;

                try
                {
                    oClusterNameDictionary.Add(
                        sClusterName, oClusterInformation);
                }
                catch (ArgumentException)
                {
                    Range oInvalidCell = oRow.GetRangeForCell(
                        ClusterTableColumnNames.Name);

                    OnWorkbookFormatError(String.Format(

                                              "The cell {0} contains a duplicate cluster name.  There"
                                              + " can't be two rows with the same cluster name."
                                              ,
                                              ExcelUtil.GetRangeAddress(oInvalidCell)
                                              ),

                                          oInvalidCell
                                          );
                }
            }

            return(oClusterNameDictionary);
        }
        Convert <TGroup>
        (
            ICollection <TGroup> groups,
            GroupToGroupVertices <TGroup> groupToGroupVertices
        )
        {
            Debug.Assert(groups != null);
            Debug.Assert(groupToGroupVertices != null);

            // These columns are needed:
            //
            // * Group name on the group worksheet.
            //
            // * Vertex color on the group worksheet.
            //
            // * Vertex shape on the group worksheet.
            //
            // * Collapsed flag on the group worksheet.
            //
            // * Group name on the group-vertex worksheet.
            //
            // * Vertex name on the group-vertex worksheet.
            //
            // * Vertex ID on the group-vertex worksheet.  This gets copied from
            //   the hidden ID column on the Vertex worksheet via an Excel
            //   formula.


            List <GraphMetricValueOrdered> oGroupNamesForGroupWorksheet =
                new List <GraphMetricValueOrdered>();

            List <GraphMetricValueOrdered> oVertexColorsForGroupWorksheet =
                new List <GraphMetricValueOrdered>();

            List <GraphMetricValueOrdered> oVertexShapesForGroupWorksheet =
                new List <GraphMetricValueOrdered>();

            // This column is empty.

            GraphMetricValueOrdered [] aoCollapsedFlagsForGroupWorksheet =
                new GraphMetricValueOrdered[0];

            List <GraphMetricValueOrdered> oGroupNamesForGroupVertexWorksheet =
                new List <GraphMetricValueOrdered>();

            List <GraphMetricValueOrdered> oVertexNamesForGroupVertexWorksheet =
                new List <GraphMetricValueOrdered>();

            // This column contains a constant value, which is a formula.

            GraphMetricValueOrdered [] aoVertexIDsForGroupVertexWorksheet =
            {
                new GraphMetricValueOrdered(
                    GroupManager.GetExcelFormulaForVertexID())
            };

            Int32 iGroups = groups.Count;
            Int32 iGroup  = 0;

            ColorConverter2 oColorConverter2 = new ColorConverter2();

            VertexShapeConverter oVertexShapeConverter =
                new VertexShapeConverter();

            foreach (TGroup oGroup in groups)
            {
                String sGroupName = 'G' + (iGroup + 1).ToString(
                    CultureInfo.InvariantCulture);

                Color       oColor;
                VertexShape eShape;

                GroupManager.GetVertexAttributes(iGroup, iGroups, out oColor,
                                                 out eShape);

                GraphMetricValueOrdered oGroupNameGraphMetricValue =
                    new GraphMetricValueOrdered(sGroupName);

                oGroupNamesForGroupWorksheet.Add(oGroupNameGraphMetricValue);

                // Write the color in a format that is understood by
                // ColorConverter2.WorkbookToGraph(), which is what
                // WorksheetReaderBase uses.

                oVertexColorsForGroupWorksheet.Add(
                    new GraphMetricValueOrdered(
                        oColorConverter2.GraphToWorkbook(oColor)));

                oVertexShapesForGroupWorksheet.Add(
                    new GraphMetricValueOrdered(
                        oVertexShapeConverter.GraphToWorkbook(eShape)));

                Int32 iVertices = 0;

                foreach (IVertex oVertex in groupToGroupVertices(oGroup))
                {
                    oGroupNamesForGroupVertexWorksheet.Add(
                        oGroupNameGraphMetricValue);

                    oVertexNamesForGroupVertexWorksheet.Add(
                        new GraphMetricValueOrdered(
                            ExcelUtil.ForceCellText(oVertex.Name)));

                    iVertices++;
                }

                iGroup++;
            }

            return(new GraphMetricColumn [] {
                new GraphMetricColumnOrdered(WorksheetNames.Groups,
                                             TableNames.Groups,
                                             GroupTableColumnNames.Name,
                                             ExcelUtil.AutoColumnWidth, null, CellStyleNames.Required,
                                             oGroupNamesForGroupWorksheet.ToArray()
                                             ),

                new GraphMetricColumnOrdered(WorksheetNames.Groups,
                                             TableNames.Groups,
                                             GroupTableColumnNames.VertexColor,
                                             ExcelUtil.AutoColumnWidth, null, CellStyleNames.VisualProperty,
                                             oVertexColorsForGroupWorksheet.ToArray()
                                             ),

                new GraphMetricColumnOrdered(WorksheetNames.Groups,
                                             TableNames.Groups,
                                             GroupTableColumnNames.VertexShape,
                                             ExcelUtil.AutoColumnWidth, null, CellStyleNames.VisualProperty,
                                             oVertexShapesForGroupWorksheet.ToArray()
                                             ),

                new GraphMetricColumnOrdered(WorksheetNames.Groups,
                                             TableNames.Groups,
                                             GroupTableColumnNames.Collapsed,
                                             ExcelUtil.AutoColumnWidth, null, CellStyleNames.VisualProperty,
                                             aoCollapsedFlagsForGroupWorksheet
                                             ),

                new GraphMetricColumnOrdered(WorksheetNames.GroupVertices,
                                             TableNames.GroupVertices,
                                             GroupVertexTableColumnNames.GroupName,
                                             ExcelUtil.AutoColumnWidth, null, null,
                                             oGroupNamesForGroupVertexWorksheet.ToArray()
                                             ),

                new GraphMetricColumnOrdered(WorksheetNames.GroupVertices,
                                             TableNames.GroupVertices,
                                             GroupVertexTableColumnNames.VertexName,
                                             ExcelUtil.AutoColumnWidth, null, null,
                                             oVertexNamesForGroupVertexWorksheet.ToArray()
                                             ),

                new GraphMetricColumnOrdered(WorksheetNames.GroupVertices,
                                             TableNames.GroupVertices,
                                             GroupVertexTableColumnNames.VertexID,
                                             ExcelUtil.AutoColumnWidth, null, null,
                                             aoVertexIDsForGroupVertexWorksheet
                                             ),
            });
        }
        //*************************************************************************
        //  Constructor: ReadWorkbookContext()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadWorkbookContext" />
        /// class.
        /// </summary>
        //*************************************************************************
        public ReadWorkbookContext()
        {
            m_bIgnoreVertexLocations = true;
            m_bFillIDColumns = false;
            m_bPopulateVertexWorksheet = false;
            m_bReadEdgeWeights = false;
            m_bReadGroups = false;
            m_bSaveGroupVertices = false;
            m_bReadVertexLabels = false;
            m_bReadEdgeLabels = false;
            m_bReadVertexImages = false;
            m_oDefaultVertexImageSize = new Nullable<Single>();
            m_eDefaultVertexShape = VertexShape.Disk;
            m_bReadAllEdgeAndVertexColumns = false;
            m_oGraphRectangle = Rectangle.FromLTRB(0, 0, 100, 100);
            m_oColorConverter2 = new ColorConverter2();
            m_oBooleanConverter = new BooleanConverter();
            m_oEdgeWidthConverter = new EdgeWidthConverter();
            m_oEdgeStyleConverter = new EdgeStyleConverter();
            m_oVertexRadiusConverter = new VertexRadiusConverter();

            m_oVertexLocationConverter =
            new VertexLocationConverter(m_oGraphRectangle);

            m_oVertexNameDictionary = new Dictionary<String, IVertex>();
            m_oEdgeRowIDDictionary = new Dictionary<Int32, IIdentityProvider>();
            m_oVertexRowIDDictionary = new Dictionary<Int32, IIdentityProvider>();

            AssertValid();
        }
Exemple #18
0
        ReadGroupTable
        (
            ListObject oGroupTable,
            ReadWorkbookContext oReadWorkbookContext
        )
        {
            Debug.Assert(oGroupTable != null);
            Debug.Assert(oReadWorkbookContext != null);
            AssertValid();

            if (oReadWorkbookContext.FillIDColumns)
            {
                FillIDColumn(oGroupTable);
            }

            Dictionary <String, GroupInformation> oGroupNameDictionary =
                new Dictionary <String, GroupInformation>();

            ColorConverter2 oColorConverter2 =
                oReadWorkbookContext.ColorConverter2;

            BooleanConverter oBooleanConverter =
                oReadWorkbookContext.BooleanConverter;

            ExcelTableReader oExcelTableReader = new ExcelTableReader(oGroupTable);

            foreach (ExcelTableReader.ExcelTableRow oRow in
                     oExcelTableReader.GetRows())
            {
                // Get the group information.

                String      sGroupName;
                Color       oVertexColor;
                VertexShape eVertexShape;

                if (
                    !oRow.TryGetNonEmptyStringFromCell(GroupTableColumnNames.Name,
                                                       out sGroupName)
                    ||
                    !TryGetColor(oRow, GroupTableColumnNames.VertexColor,
                                 oColorConverter2, out oVertexColor)
                    ||
                    !TryGetVertexShape(oRow, GroupTableColumnNames.VertexShape,
                                       out eVertexShape)
                    )
                {
                    continue;
                }

                Boolean bCollapsed = false;
                Boolean bCollapsedCellValue;

                if (
                    TryGetBoolean(oRow, GroupTableColumnNames.Collapsed,
                                  oBooleanConverter, out bCollapsedCellValue)
                    &&
                    bCollapsedCellValue
                    )
                {
                    bCollapsed = true;
                }

                Int32            iRowIDAsInt32;
                Nullable <Int32> iRowID = null;

                if (oRow.TryGetInt32FromCell(CommonTableColumnNames.ID,
                                             out iRowIDAsInt32))
                {
                    iRowID = iRowIDAsInt32;
                }

                GroupInformation oGroupInformation = new GroupInformation(
                    sGroupName, iRowID, oVertexColor, eVertexShape, bCollapsed);

                if (oReadWorkbookContext.SaveGroupVertices)
                {
                    // ReadGroupVertexTable() will save the group's vertices in
                    // this LinkedList.

                    oGroupInformation.Vertices = new LinkedList <IVertex>();
                }

                try
                {
                    oGroupNameDictionary.Add(sGroupName, oGroupInformation);
                }
                catch (ArgumentException)
                {
                    Range oInvalidCell = oRow.GetRangeForCell(
                        GroupTableColumnNames.Name);

                    OnWorkbookFormatError(String.Format(

                                              "The cell {0} contains a duplicate group name.  There"
                                              + " can't be two rows with the same group name."
                                              ,
                                              ExcelUtil.GetRangeAddress(oInvalidCell)
                                              ),

                                          oInvalidCell
                                          );
                }
            }

            return(oGroupNameDictionary);
        }