//************************************************************************* // 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_bReadVertexColorFromGroups = true; m_bReadVertexShapeFromGroups = true; m_bReadVertexLabels = false; m_bReadEdgeLabels = false; m_bReadGroupLabels = 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_oFontSizeConverter = new FontSizeConverter(); 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(); }
ReadRadius ( ExcelTableReader.ExcelTableRow oRow, VertexRadiusConverter oVertexRadiusConverter, IVertex oVertex ) { Debug.Assert(oRow != null); Debug.Assert(oVertex != null); Debug.Assert(oVertexRadiusConverter != null); AssertValid(); String sRadius; if (!oRow.TryGetNonEmptyStringFromCell(VertexTableColumnNames.Radius, out sRadius)) { return(new Nullable <Single>()); } Single fRadius; if (!Single.TryParse(sRadius, out fRadius)) { Range oInvalidCell = oRow.GetRangeForCell( VertexTableColumnNames.Radius); OnWorkbookFormatError(String.Format( "The cell {0} contains an invalid size. The vertex size," + " which is optional, must be a number. Any number is" + " acceptable, although {1} is used for any number less than" + " {1} and {2} is used for any number greater than {2}." , ExcelUtil.GetRangeAddress(oInvalidCell), VertexRadiusConverter.MinimumRadiusWorkbook, VertexRadiusConverter.MaximumRadiusWorkbook ), oInvalidCell ); } oVertex.SetValue(ReservedMetadataKeys.PerVertexRadius, oVertexRadiusConverter.WorkbookToGraph(fRadius)); return(new Nullable <Single>(fRadius)); }
//************************************************************************* // 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_bReadVertexColorFromGroups = true; m_bReadVertexShapeFromGroups = true; m_bReadVertexLabels = false; m_bReadEdgeLabels = false; m_bReadGroupLabels = 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_oFontSizeConverter = new FontSizeConverter(); 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(); }
ReadImageUri ( ExcelTableReader.ExcelTableRow oRow, IVertex oVertex, VertexRadiusConverter oVertexRadiusConverter, Nullable <Single> oVertexImageSize ) { Debug.Assert(oRow != null); Debug.Assert(oVertex != null); Debug.Assert(oVertexRadiusConverter != null); AssertValid(); String sImageUri; if (!oRow.TryGetNonEmptyStringFromCell( VertexTableColumnNames.ImageUri, out sImageUri)) { return(false); } if (sImageUri.ToLower().StartsWith("www.")) { // The Uri class thinks that "www.somewhere.com" is a relative // path. Fix that. sImageUri = "http://" + sImageUri; } Uri oUri; // Is the URI either an URL or a full file path? if (!Uri.TryCreate(sImageUri, UriKind.Absolute, out oUri)) { // No. It appears to be a relative path. Range oCell = oRow.GetRangeForCell( VertexTableColumnNames.ImageUri); String sWorkbookPath = ((Workbook)(oCell.Worksheet.Parent)).Path; if (!String.IsNullOrEmpty(sWorkbookPath)) { sImageUri = Path.Combine(sWorkbookPath, sImageUri); } else { OnWorkbookFormatError(String.Format( "The image file path specified in cell {0} is a relative" + " path. Relative paths must be relative to the saved" + " workbook file, but the workbook hasn't been saved yet." + " Either save the workbook or change the image file to" + " an absolute path, such as \"C:\\MyImages\\Image.jpg\"." , ExcelUtil.GetRangeAddress(oCell) ), oCell ); } } // Note that sImageUri may or may not be a valid URI string. If it is // not, GetImageSynchronousIgnoreDpi() will return an error image. BitmapSource oImage = (new WpfImageUtil()).GetImageSynchronousIgnoreDpi(sImageUri); if (oVertexImageSize.HasValue) { // Resize the image. Double dLongerDimension = oVertexRadiusConverter.WorkbookToLongerImageDimension( oVertexImageSize.Value); Debug.Assert(dLongerDimension >= 1); oImage = (new WpfImageUtil()).ResizeImage(oImage, (Int32)dLongerDimension); } oVertex.SetValue(ReservedMetadataKeys.PerVertexImage, oImage); return(true); }
ReadImageUri ( ExcelTableReader.ExcelTableRow oRow, IVertex oVertex, VertexRadiusConverter oVertexRadiusConverter, Nullable<Single> oVertexImageSize ) { Debug.Assert(oRow != null); Debug.Assert(oVertex != null); Debug.Assert(oVertexRadiusConverter != null); AssertValid(); String sImageUri; if ( !oRow.TryGetNonEmptyStringFromCell( VertexTableColumnNames.ImageUri, out sImageUri) ) { return (false); } if ( sImageUri.ToLower().StartsWith("www.") ) { // The Uri class thinks that "www.somewhere.com" is a relative // path. Fix that. sImageUri= "http://" + sImageUri; } Uri oUri; // Is the URI either an URL or a full file path? if ( !Uri.TryCreate(sImageUri, UriKind.Absolute, out oUri) ) { // No. It appears to be a relative path. Range oCell = oRow.GetRangeForCell( VertexTableColumnNames.ImageUri); String sWorkbookPath = ( (Workbook)(oCell.Worksheet.Parent) ).Path; if ( !String.IsNullOrEmpty(sWorkbookPath) ) { sImageUri = Path.Combine(sWorkbookPath, sImageUri); } else { OnWorkbookFormatError( String.Format( "The image file path specified in cell {0} is a relative" + " path. Relative paths must be relative to the saved" + " workbook file, but the workbook hasn't been saved yet." + " Either save the workbook or change the image file to" + " an absolute path, such as \"C:\\MyImages\\Image.jpg\"." , ExcelUtil.GetRangeAddress(oCell) ), oCell ); } } // Note that sImageUri may or may not be a valid URI string. If it is // not, GetImageSynchronousIgnoreDpi() will return an error image. ImageSource oImage = ( new WpfImageUtil() ).GetImageSynchronousIgnoreDpi(sImageUri); if (oVertexImageSize.HasValue) { // Resize the image. Double dLongerDimension = oVertexRadiusConverter.WorkbookToLongerImageDimension( oVertexImageSize.Value); Debug.Assert(dLongerDimension >= 1); oImage = ( new WpfImageUtil() ).ResizeImage(oImage, (Int32)dLongerDimension); } oVertex.SetValue(ReservedMetadataKeys.PerVertexImage, oImage); return (true); }
ReadRadius ( ExcelTableReader.ExcelTableRow oRow, VertexRadiusConverter oVertexRadiusConverter, IVertex oVertex ) { Debug.Assert(oRow != null); Debug.Assert(oVertex != null); Debug.Assert(oVertexRadiusConverter != null); AssertValid(); String sRadius; if ( !oRow.TryGetNonEmptyStringFromCell(VertexTableColumnNames.Radius, out sRadius) ) { return ( new Nullable<Single>() ); } Single fRadius; if ( !Single.TryParse(sRadius, out fRadius) ) { Range oInvalidCell = oRow.GetRangeForCell( VertexTableColumnNames.Radius); OnWorkbookFormatError( String.Format( "The cell {0} contains an invalid size. The vertex size," + " which is optional, must be a number. Any number is" + " acceptable, although {1} is used for any number less than" + " {1} and {2} is used for any number greater than {2}." , ExcelUtil.GetRangeAddress(oInvalidCell), VertexRadiusConverter.MinimumRadiusWorkbook, VertexRadiusConverter.MaximumRadiusWorkbook ), oInvalidCell ); } oVertex.SetValue( ReservedMetadataKeys.PerVertexRadius, oVertexRadiusConverter.WorkbookToGraph(fRadius) ); return ( new Nullable<Single>(fRadius) ); }
SetUp() { m_oVertexRadiusConverter = new VertexRadiusConverter(); }
btnOK_Click ( object sender, EventArgs e ) { AssertValid(); if (!DoDataExchange(true)) { return; } // If the caller is going to force the workbook to be reread, there // is no point in editing the vertices' metadata. if (!m_oEditedVertexAttributes.WorkbookMustBeReread) { this.UseWaitCursor = true; VertexRadiusConverter oVertexRadiusConverter = new VertexRadiusConverter(); AlphaConverter oAlphaConverter = new AlphaConverter(); foreach (IVertex oVertex in m_oNodeXLControl.SelectedVertices) { SetValue <Color>(oVertex, ReservedMetadataKeys.PerColor, m_oEditedVertexAttributes.Color); SetValue <VertexShape>(oVertex, ReservedMetadataKeys.PerVertexShape, m_oEditedVertexAttributes.Shape); SetSingleValue(oVertex, ReservedMetadataKeys.PerVertexRadius, m_oEditedVertexAttributes.Radius, oVertexRadiusConverter); SetSingleValue(oVertex, ReservedMetadataKeys.PerAlpha, m_oEditedVertexAttributes.Alpha, oAlphaConverter); if (m_oEditedVertexAttributes.Visibility.HasValue) { Debug.Assert(m_oEditedVertexAttributes.Visibility.Value == VertexWorksheetReader.Visibility.Hide); // Hide the vertex and its incident edges. oVertex.SetValue(ReservedMetadataKeys.Visibility, VisibilityKeyValue.Hidden); foreach (IEdge oIncidentEdge in oVertex.IncidentEdges) { oIncidentEdge.SetValue(ReservedMetadataKeys.Visibility, VisibilityKeyValue.Hidden); } } SetStringValue(oVertex, ReservedMetadataKeys.PerVertexLabel, m_oEditedVertexAttributes.Label); SetValue <Color>(oVertex, ReservedMetadataKeys.PerVertexLabelFillColor, m_oEditedVertexAttributes.LabelFillColor); SetValue <VertexLabelPosition>(oVertex, ReservedMetadataKeys.PerVertexLabelPosition, m_oEditedVertexAttributes.LabelPosition); SetStringValue(oVertex, ReservedMetadataKeys.PerVertexToolTip, m_oEditedVertexAttributes.ToolTip); SetValue <Boolean>(oVertex, ReservedMetadataKeys.LockVertexLocation, m_oEditedVertexAttributes.Locked); SetValue <Boolean>(oVertex, ReservedMetadataKeys.Marked, m_oEditedVertexAttributes.Marked); } m_oNodeXLControl.DrawGraph(); this.UseWaitCursor = false; } DialogResult = DialogResult.OK; this.Close(); }