ReadLocked ( ExcelTableReader.ExcelTableRow oRow, BooleanConverter oBooleanConverter, Boolean bLocationSpecified, IVertex oVertex ) { Debug.Assert(oRow != null); Debug.Assert(oBooleanConverter != null); Debug.Assert(oVertex != null); AssertValid(); Boolean bLocked; if (!TryGetBoolean(oRow, VertexTableColumnNames.Locked, oBooleanConverter, out bLocked)) { return; } if (bLocked && !bLocationSpecified) { Range oInvalidCell = oRow.GetRangeForCell( VertexTableColumnNames.Locked); OnWorkbookFormatError(String.Format( "The cell {0} indicates that the vertex should be locked," + " but the vertex has no X and Y location values. Either" + " clear the lock or specify a vertex location." , ExcelUtil.GetRangeAddress(oInvalidCell) ), oInvalidCell ); } oVertex.SetValue(ReservedMetadataKeys.LockVertexLocation, bLocked); }
ReadMarked ( ExcelTableReader.ExcelTableRow oRow, BooleanConverter oBooleanConverter, IVertex oVertex ) { Debug.Assert(oRow != null); Debug.Assert(oBooleanConverter != null); Debug.Assert(oVertex != null); AssertValid(); Boolean bMarked; if (!TryGetBoolean(oRow, VertexTableColumnNames.IsMarked, oBooleanConverter, out bMarked)) { return; } oVertex.SetValue(ReservedMetadataKeys.Marked, bMarked); return; }
ReadVertexTable ( ListObject oVertexTable, ReadWorkbookContext oReadWorkbookContext, IGraph oGraph, out Boolean bLayoutAndZOrderSet ) { Debug.Assert(oVertexTable != null); Debug.Assert(oReadWorkbookContext != null); Debug.Assert(oGraph != null); AssertValid(); bLayoutAndZOrderSet = false; if (GetTableColumnIndex(oVertexTable, VertexTableColumnNames.VertexName, false) == NoSuchColumn) { // Nothing can be done without vertex names. return; } Boolean bReadAllEdgeAndVertexColumns = oReadWorkbookContext.ReadAllEdgeAndVertexColumns; if (oReadWorkbookContext.FillIDColumns) { FillIDColumn(oVertexTable); } // Get the names of all the column pairs that are used to add custom // menu items to the vertex context menu in the graph. TableColumnAdder oTableColumnAdder = new TableColumnAdder(); ICollection <KeyValuePair <String, String> > aoCustomMenuItemPairNames = oTableColumnAdder.GetColumnPairNames(oVertexTable, VertexTableColumnNames.CustomMenuItemTextBase, VertexTableColumnNames.CustomMenuItemActionBase); IVertexCollection oVertices = oGraph.Vertices; Dictionary <String, IVertex> oVertexNameDictionary = oReadWorkbookContext.VertexNameDictionary; Dictionary <Int32, IIdentityProvider> oEdgeRowIDDictionary = oReadWorkbookContext.EdgeRowIDDictionary; BooleanConverter oBooleanConverter = oReadWorkbookContext.BooleanConverter; VertexVisibilityConverter oVertexVisibilityConverter = new VertexVisibilityConverter(); VertexLabelPositionConverter oVertexLabelPositionConverter = new VertexLabelPositionConverter(); ExcelTableReader oExcelTableReader = new ExcelTableReader(oVertexTable); HashSet <String> oColumnNamesToExclude = new HashSet <String>( new String[] { VertexTableColumnNames.VertexName }); foreach (ExcelTableReader.ExcelTableRow oRow in oExcelTableReader.GetRows()) { // Get the name of the vertex. String sVertexName; if (!oRow.TryGetNonEmptyStringFromCell( VertexTableColumnNames.VertexName, out sVertexName)) { continue; } // If the vertex was added to the graph as part of an edge, // retrieve the vertex. IVertex oVertex; if (!oVertexNameDictionary.TryGetValue(sVertexName, out oVertex)) { oVertex = null; } // Assume a default visibility. Visibility eVisibility = Visibility.ShowIfInAnEdge; String sVisibility; if (oRow.TryGetNonEmptyStringFromCell( CommonTableColumnNames.Visibility, out sVisibility)) { if (!oVertexVisibilityConverter.TryWorkbookToGraph( sVisibility, out eVisibility)) { OnInvalidVisibility(oRow); } } switch (eVisibility) { case Visibility.ShowIfInAnEdge: // If the vertex is part of an edge, show it using the // specified vertex attributes. Otherwise, skip the vertex // row. if (oVertex == null) { continue; } break; case Visibility.Skip: // Skip the vertex row and any edge rows that include the // vertex. Do not read them into the graph. if (oVertex != null) { // Remove the vertex and its incident edges from the // graph and dictionaries. RemoveVertex(oVertex, oReadWorkbookContext, oGraph); } continue; case Visibility.Hide: // If the vertex is part of an edge, hide it and its // incident edges. Otherwise, skip the vertex row. if (oVertex == null) { continue; } HideVertex(oVertex); break; case Visibility.Show: // Show the vertex using the specified attributes // regardless of whether it is part of an edge. if (oVertex == null) { oVertex = CreateVertex(sVertexName, oVertices, oVertexNameDictionary); } oVertex.SetValue( ReservedMetadataKeys.VertexHasVisibilityOfShow, null); break; default: Debug.Assert(false); break; } Debug.Assert(oVertex != null); // If ReadWorkbookContext.FillIDColumns is true, add the vertex to // the vertex row ID dictionary and set the vertex's Tag to the row // ID. oReadWorkbookContext.AddToRowIDDictionary(oRow, oVertex, false); if (bReadAllEdgeAndVertexColumns) { // All columns except the vertex name should be read and stored // as metadata on the vertex. ReadAllColumns(oExcelTableReader, oRow, oVertex, oColumnNamesToExclude); continue; } // Layout and z-order. if (ReadLayoutAndZOrder(oRow, oVertex)) { bLayoutAndZOrderSet = true; } // Location and Locked. if (!oReadWorkbookContext.IgnoreVertexLocations) { System.Drawing.PointF oLocation; Boolean bLocationSpecified = TryGetLocation(oRow, VertexTableColumnNames.X, VertexTableColumnNames.Y, oReadWorkbookContext.VertexLocationConverter, out oLocation); if (bLocationSpecified) { oVertex.Location = oLocation; } ReadLocked(oRow, oBooleanConverter, bLocationSpecified, oVertex); } // Polar coordinates. ReadPolarCoordinates(oRow, oVertex); // Marked. ReadMarked(oRow, oBooleanConverter, oVertex); // Custom menu items. if (aoCustomMenuItemPairNames.Count > 0) { ReadCustomMenuItems(oRow, aoCustomMenuItemPairNames, oVertex); } // Alpha. ReadAlpha(oRow, oVertex); // Tooltip. ReadCellAndSetMetadata(oRow, VertexTableColumnNames.ToolTip, oVertex, ReservedMetadataKeys.PerVertexToolTip); // Label. if (oReadWorkbookContext.ReadVertexLabels) { ReadCellAndSetMetadata(oRow, VertexTableColumnNames.Label, oVertex, ReservedMetadataKeys.PerVertexLabel); } // Label fill color. ReadColor(oRow, VertexTableColumnNames.LabelFillColor, oVertex, ReservedMetadataKeys.PerVertexLabelFillColor, oReadWorkbookContext.ColorConverter2); // Label position. ReadLabelPosition(oRow, oVertexLabelPositionConverter, oVertex); // Radius. Nullable <Single> oRadiusWorkbook = new Nullable <Single>(); oRadiusWorkbook = ReadRadius(oRow, oReadWorkbookContext.VertexRadiusConverter, oVertex); // Shape. VertexShape eVertexShape; if (!ReadShape(oRow, oVertex, out eVertexShape)) { eVertexShape = oReadWorkbookContext.DefaultVertexShape; } // Label font size. if (eVertexShape == VertexShape.Label && oRadiusWorkbook.HasValue) { // The vertex radius is used to specify font size when the // shape is Label. oVertex.SetValue(ReservedMetadataKeys.PerVertexLabelFontSize, oReadWorkbookContext.VertexRadiusConverter. WorkbookToLabelFontSize(oRadiusWorkbook.Value)); } // Image URI. if (eVertexShape == VertexShape.Image && oReadWorkbookContext.ReadVertexImages) { ReadImageUri(oRow, oVertex, oReadWorkbookContext.VertexRadiusConverter, oRadiusWorkbook.HasValue ? oRadiusWorkbook : oReadWorkbookContext.DefaultVertexImageSize ); } // Color ReadColor(oRow, VertexTableColumnNames.Color, oVertex, ReservedMetadataKeys.PerColor, oReadWorkbookContext.ColorConverter2); } if (bReadAllEdgeAndVertexColumns) { // Store the vertex column names on the graph. oGraph.SetValue(ReservedMetadataKeys.AllVertexMetadataKeys, FilterColumnNames(oExcelTableReader, oColumnNamesToExclude)); } }
ReadGroupTable ( ListObject oGroupTable, ReadWorkbookContext oReadWorkbookContext, HashSet <String> oSkippedGroupNames, HashSet <String> oHiddenGroupNames ) { Debug.Assert(oGroupTable != null); Debug.Assert(oReadWorkbookContext != null); Debug.Assert(oSkippedGroupNames != null); Debug.Assert(oHiddenGroupNames != null); AssertValid(); if (oReadWorkbookContext.FillIDColumns) { FillIDColumn(oGroupTable); } Dictionary <String, ExcelTemplateGroupInfo> oGroupNameDictionary = new Dictionary <String, ExcelTemplateGroupInfo>(); ColorConverter2 oColorConverter2 = oReadWorkbookContext.ColorConverter2; GroupVisibilityConverter oGroupVisibilityConverter = new GroupVisibilityConverter(); 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; } ReadVisibility(oRow, oGroupVisibilityConverter, sGroupName, oSkippedGroupNames, oHiddenGroupNames); Boolean bCollapsed = false; Boolean bCollapsedCellValue; if ( TryGetBoolean(oRow, GroupTableColumnNames.Collapsed, oBooleanConverter, out bCollapsedCellValue) && bCollapsedCellValue ) { bCollapsed = true; } String sCollapsedAttributes; if (!oRow.TryGetNonEmptyStringFromCell( GroupTableColumnNames.CollapsedAttributes, out sCollapsedAttributes)) { sCollapsedAttributes = null; } Int32 iRowIDAsInt32; Nullable <Int32> iRowID = null; if (oRow.TryGetInt32FromCell(CommonTableColumnNames.ID, out iRowIDAsInt32)) { iRowID = iRowIDAsInt32; } ExcelTemplateGroupInfo oExcelTemplateGroupInfo = new ExcelTemplateGroupInfo(sGroupName, iRowID, oVertexColor, eVertexShape, bCollapsed, sCollapsedAttributes); if (oReadWorkbookContext.ReadGroupLabels) { String sLabel; if (oRow.TryGetNonEmptyStringFromCell( GroupTableColumnNames.Label, out sLabel)) { oExcelTemplateGroupInfo.Label = sLabel; } } if (!oReadWorkbookContext.IgnoreVertexLocations) { System.Drawing.PointF oCollapsedLocation; if (TryGetLocation(oRow, GroupTableColumnNames.CollapsedX, GroupTableColumnNames.CollapsedY, oReadWorkbookContext.VertexLocationConverter, out oCollapsedLocation)) { oExcelTemplateGroupInfo.CollapsedLocation = oCollapsedLocation; } } try { oGroupNameDictionary.Add(sGroupName, oExcelTemplateGroupInfo); } 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); }
TryCalculateGraphMetrics ( IGraph graph, CalculateGraphMetricsContext calculateGraphMetricsContext, out GraphMetricColumn [] graphMetricColumns ) { Debug.Assert(graph != null); Debug.Assert(calculateGraphMetricsContext != null); AssertValid(); graphMetricColumns = new GraphMetricColumn[0]; if ( graph.Directedness != GraphDirectedness.Directed || !calculateGraphMetricsContext.ShouldCalculateGraphMetrics( GraphMetrics.EdgeReciprocation) ) { return(true); } // Calculate the reciprocated flag for each edge using the // EdgeReciprocationCalculator class in the Algorithms namespace, which // knows nothing about Excel. Dictionary <Int32, Boolean> oReciprocatedFlags; if (!(new Algorithms.EdgeReciprocationCalculator()). TryCalculateGraphMetrics(graph, calculateGraphMetricsContext.BackgroundWorker, out oReciprocatedFlags)) { // The user cancelled. return(false); } // Transfer the flags to an array of GraphMetricValue objects. List <GraphMetricValueWithID> oReciprocatedValues = new List <GraphMetricValueWithID>(); BooleanConverter oBooleanConverter = new BooleanConverter(); foreach (IEdge oEdge in graph.Edges) { // Try to get the row ID stored in the worksheet. Int32 iRowID; if (TryGetRowID(oEdge, out iRowID)) { oReciprocatedValues.Add( new GraphMetricValueWithID(iRowID, oBooleanConverter.GraphToWorkbook( oReciprocatedFlags[oEdge.ID]) )); } } graphMetricColumns = new GraphMetricColumn [] { new GraphMetricColumnWithID(WorksheetNames.Edges, TableNames.Edges, EdgeTableColumnNames.IsReciprocated, ExcelTableUtil.AutoColumnWidth, null, CellStyleNames.GraphMetricGood, oReciprocatedValues.ToArray() ), }; return(true); }
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.EditedVertexAttributes == null || !m_oSheets1And2Helper.TableExists || !m_oSheets1And2Helper.TryGetAllRowIDs(out oRowIDDictionary) ) { return; } Microsoft.Office.Interop.Excel.ListObject oVertexTable = Vertices.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, oShapeColumnData, oRadiusColumnData, oAlphaColumnData, oVisibilityColumnData, oLabelColumnData, oLabelFillColorColumnData, oLabelPositionColumnData, oToolTipColumnData, oLockedColumnData, oMarkedColumnData; Object [,] aoColorValues = null; Object [,] aoShapeValues = null; Object [,] aoRadiusValues = null; Object [,] aoAlphaValues = null; Object [,] aoVisibilityValues = null; Object [,] aoLabelValues = null; Object [,] aoLabelFillColorValues = null; Object [,] aoLabelPositionValues = null; Object [,] aoToolTipValues = null; Object [,] aoLockedValues = null; Object [,] aoMarkedValues = null; ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable, VertexTableColumnNames.Color, out oColorColumnData, out aoColorValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable, VertexTableColumnNames.Shape, out oShapeColumnData, out aoShapeValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable, VertexTableColumnNames.Radius, out oRadiusColumnData, out aoRadiusValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable, CommonTableColumnNames.Alpha, out oAlphaColumnData, out aoAlphaValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable, CommonTableColumnNames.Visibility, out oVisibilityColumnData, out aoVisibilityValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable, VertexTableColumnNames.Label, out oLabelColumnData, out aoLabelValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable, VertexTableColumnNames.LabelFillColor, out oLabelFillColorColumnData, out aoLabelFillColorValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable, VertexTableColumnNames.LabelPosition, out oLabelPositionColumnData, out aoLabelPositionValues); ExcelTableUtil.TryGetTableColumnDataAndValues(oVertexTable, VertexTableColumnNames.ToolTip, out oToolTipColumnData, out aoToolTipValues); ExcelTableUtil.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 (!String.IsNullOrEmpty(oEditedVertexAttributes.Label)) { aoLabelValues[iRowOneBased, 1] = oEditedVertexAttributes.Label; } if (oEditedVertexAttributes.LabelFillColor.HasValue && aoLabelFillColorValues != null) { aoLabelFillColorValues[iRowOneBased, 1] = oColorConverter2.GraphToWorkbook( oEditedVertexAttributes.LabelFillColor.Value); } if (oEditedVertexAttributes.LabelPosition.HasValue && aoLabelPositionValues != null) { aoLabelPositionValues[iRowOneBased, 1] = oVertexLabelPositionConverter.GraphToWorkbook( oEditedVertexAttributes.LabelPosition.Value); } if (!String.IsNullOrEmpty(oEditedVertexAttributes.ToolTip)) { aoToolTipValues[iRowOneBased, 1] = oEditedVertexAttributes.ToolTip; } 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 = m_oSheets1And2Helper.GetExcelActiveWorksheetRestorer(); ExcelActiveWorksheetState oExcelActiveWorksheetState = oExcelActiveWorksheetRestorer.ActivateWorksheet(this.InnerObject); try { m_oSheets1And2Helper.SetColumnDataValues( oColorColumnData, aoColorValues, oShapeColumnData, aoShapeValues, oRadiusColumnData, aoRadiusValues, oAlphaColumnData, aoAlphaValues, oVisibilityColumnData, aoVisibilityValues, oLabelColumnData, aoLabelValues, oLabelFillColorColumnData, aoLabelFillColorValues, oLabelPositionColumnData, aoLabelPositionValues, oToolTipColumnData, aoToolTipValues, oLockedColumnData, aoLockedValues, oMarkedColumnData, aoMarkedValues ); } finally { oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState); } Globals.ThisWorkbook.ShowWaitCursor = false; }
//************************************************************************* // Constructor: VertexAttributesDialog() // /// <summary> /// Initializes a new instance of the <see cref="VertexAttributesDialog" /> /// class. /// </summary> /// /// <param name="nodeXLControl"> /// NodeXLControl whose vertex attributes need to be edited. /// </param> //************************************************************************* public VertexAttributesDialog ( NodeXLControl nodeXLControl ) : base(nodeXLControl) { InitializeComponent(); // Instantiate an object that retrieves and saves the user settings for // this dialog. Note that the object automatically saves the settings // when the form closes. m_oVertexAttributesDialogUserSettings = new VertexAttributesDialogUserSettings(this); m_oEditedVertexAttributes = GetInitialVertexAttributes(); (new VertexShapeConverter()).PopulateComboBox(cbxShape, true); nudRadius.Minimum = (Decimal)VertexRadiusConverter.MinimumRadiusWorkbook; nudRadius.Maximum = (Decimal)VertexRadiusConverter.MaximumRadiusWorkbook; nudAlpha.Minimum = (Decimal)AlphaConverter.MinimumAlphaWorkbook; nudAlpha.Maximum = (Decimal)AlphaConverter.MaximumAlphaWorkbook; VertexVisibilityConverter oVertexVisibilityConverter = new VertexVisibilityConverter(); String sHide = oVertexVisibilityConverter.GraphToWorkbook( VertexWorksheetReader.Visibility.Hide); cbxVisibility.PopulateWithObjectsAndText( NotEditedMarker, String.Empty, VertexWorksheetReader.Visibility.ShowIfInAnEdge, oVertexVisibilityConverter.GraphToWorkbook( VertexWorksheetReader.Visibility.ShowIfInAnEdge), VertexWorksheetReader.Visibility.Skip, oVertexVisibilityConverter.GraphToWorkbook( VertexWorksheetReader.Visibility.Skip), VertexWorksheetReader.Visibility.Hide, sHide, VertexWorksheetReader.Visibility.Show, oVertexVisibilityConverter.GraphToWorkbook( VertexWorksheetReader.Visibility.Show) ); SetVisibilityHelpText(lnkVisibility, sHide); (new VertexLabelPositionConverter()).PopulateComboBox( cbxLabelPosition, true); BooleanConverter oBooleanConverter = new BooleanConverter(); oBooleanConverter.PopulateComboBox(cbxLocked, true); oBooleanConverter.PopulateComboBox(cbxMarked, true); DoDataExchange(false); AssertValid(); }