TryGetVertexShape ( ExcelTableReader.ExcelTableRow oRow, String sColumnName, out VertexShape eShape ) { Debug.Assert(oRow != null); Debug.Assert(!String.IsNullOrEmpty(sColumnName)); AssertValid(); eShape = VertexShape.Circle; String sShape; if (!oRow.TryGetNonEmptyStringFromCell(sColumnName, out sShape)) { return(false); } VertexShapeConverter oVertexShapeConverter = new VertexShapeConverter(); if (!oVertexShapeConverter.TryWorkbookToGraph(sShape, out eShape)) { OnWorkbookFormatErrorWithDropDown(oRow, sColumnName, "shape"); } return(true); }
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); }
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 ), }); }
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); }
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; }