Пример #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();
        }
Пример #2
0
        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));
        }
Пример #3
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();
        }
Пример #4
0
        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;

                Boolean bApplyColor  = m_oEditedVertexAttributes.Color.HasValue;
                Boolean bApplyShape  = m_oEditedVertexAttributes.Shape.HasValue;
                Boolean bApplyRadius = m_oEditedVertexAttributes.Radius.HasValue;
                Boolean bApplyAlpha  = m_oEditedVertexAttributes.Alpha.HasValue;

                Boolean bApplyVisibility =
                    m_oEditedVertexAttributes.Visibility.HasValue;

                Boolean bApplyLabelPosition =
                    m_oEditedVertexAttributes.LabelPosition.HasValue;

                Boolean bApplyLocked = m_oEditedVertexAttributes.Locked.HasValue;
                Boolean bApplyMarked = m_oEditedVertexAttributes.Marked.HasValue;

                VertexRadiusConverter oVertexRadiusConverter =
                    new VertexRadiusConverter();

                AlphaConverter oAlphaConverter = new AlphaConverter();

                foreach (IVertex oVertex in m_oNodeXLControl.SelectedVertices)
                {
                    if (bApplyColor)
                    {
                        oVertex.SetValue(ReservedMetadataKeys.PerColor,
                                         m_oEditedVertexAttributes.Color.Value);
                    }

                    if (bApplyShape)
                    {
                        oVertex.SetValue(ReservedMetadataKeys.PerVertexShape,
                                         m_oEditedVertexAttributes.Shape.Value);
                    }

                    if (bApplyRadius)
                    {
                        oVertex.SetValue(ReservedMetadataKeys.PerVertexRadius,
                                         oVertexRadiusConverter.WorkbookToGraph(
                                             m_oEditedVertexAttributes.Radius.Value));
                    }

                    if (bApplyAlpha)
                    {
                        oVertex.SetValue(ReservedMetadataKeys.PerAlpha,
                                         oAlphaConverter.WorkbookToGraph(
                                             m_oEditedVertexAttributes.Alpha.Value));
                    }

                    if (bApplyVisibility)
                    {
                        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);
                        }
                    }

                    if (bApplyLabelPosition)
                    {
                        oVertex.SetValue(
                            ReservedMetadataKeys.PerVertexLabelPosition,
                            m_oEditedVertexAttributes.LabelPosition.Value);
                    }

                    if (bApplyLocked)
                    {
                        oVertex.SetValue(ReservedMetadataKeys.LockVertexLocation,
                                         m_oEditedVertexAttributes.Locked.Value);
                    }

                    if (bApplyMarked)
                    {
                        oVertex.SetValue(ReservedMetadataKeys.Marked,
                                         m_oEditedVertexAttributes.Marked.Value);
                    }
                }

                m_oNodeXLControl.DrawGraph();

                this.UseWaitCursor = false;
            }

            DialogResult = DialogResult.OK;
            this.Close();
        }
Пример #5
0
        GetInitialVertexAttributes()
        {
            // AssertValid();

            EditedVertexAttributes oInitialVertexAttributes =
                new EditedVertexAttributes();

            // Color.

            oInitialVertexAttributes.Color =
                GetInitialAttributeValue <Color>(ReservedMetadataKeys.PerColor);

            // Shape.

            oInitialVertexAttributes.Shape =
                GetInitialAttributeValue <VertexShape>(
                    ReservedMetadataKeys.PerVertexShape);

            // Radius.

            Nullable <Single> fInitialRadius = GetInitialAttributeValue <Single>(
                ReservedMetadataKeys.PerVertexRadius);

            if (fInitialRadius.HasValue)
            {
                // The radius values stored in the vertices are in graph units.
                // They need to be converted to workbook units.

                VertexRadiusConverter oVertexRadiusConverter =
                    new VertexRadiusConverter();

                oInitialVertexAttributes.Radius =
                    oVertexRadiusConverter.GraphToWorkbook(fInitialRadius.Value);
            }
            else
            {
                oInitialVertexAttributes.Radius = null;
            }

            // Alpha.

            Nullable <Single> fInitialAlpha = GetInitialAttributeValue <Single>(
                ReservedMetadataKeys.PerAlpha);

            if (fInitialAlpha.HasValue)
            {
                AlphaConverter oAlphaConverter = new AlphaConverter();

                oInitialVertexAttributes.Alpha = oAlphaConverter.GraphToWorkbook(
                    fInitialAlpha.Value);
            }
            else
            {
                oInitialVertexAttributes.Alpha = null;
            }

            // Visibility.

            oInitialVertexAttributes.Visibility = null;

            // Label position..

            oInitialVertexAttributes.LabelPosition =
                GetInitialAttributeValue <VertexLabelPosition>(
                    ReservedMetadataKeys.PerVertexLabelPosition);

            // Locked.

            oInitialVertexAttributes.Locked =
                GetInitialAttributeValue <Boolean>(
                    ReservedMetadataKeys.LockVertexLocation);

            // Marked.

            oInitialVertexAttributes.Marked =
                GetInitialAttributeValue <Boolean>(ReservedMetadataKeys.Marked);

            return(oInitialVertexAttributes);
        }
Пример #6
0
        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);
        }
Пример #7
0
        //*************************************************************************
        //  Method: ReadRadius()
        //
        /// <summary>
        /// If a radius has been specified for a vertex, sets the vertex's radius.
        /// </summary>
        ///
        /// <param name="oRow">
        /// Row containing the vertex data.
        /// </param>
        ///
        /// <param name="oVertexRadiusConverter">
        /// Object that converts a vertex radius between values used in the Excel
        /// workbook and values used in the NodeXL graph.
        /// </param>
        ///
        /// <param name="oVertex">
        /// Vertex to set the radius on.
        /// </param>
        ///
        /// <returns>
        /// If a radius has been specified for the vertex, the radius in workbook
        /// units is returned.  Otherwise, a Nullable that has no value is
        /// returned.
        /// </returns>
        //*************************************************************************
        protected Nullable<Single> 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) );
        }
Пример #8
0
        //*************************************************************************
        //  Method: ReadImageUri()
        //
        /// <summary>
        /// If an image URI has been specified for a vertex, sets the vertex's
        /// image.
        /// </summary>
        ///
        /// <param name="oRow">
        /// Row containing the vertex data.
        /// </param>
        ///
        /// <param name="oVertex">
        /// Vertex to set the image on.
        /// </param>
        ///
        /// <param name="oVertexRadiusConverter">
        /// Object that converts a vertex radius between values used in the Excel
        /// workbook and values used in the NodeXL graph.
        /// </param>
        ///
        /// <param name="oVertexImageSize">
        /// The size to use for the image (in workbook units), or a Nullable that
        /// has no value to use the image's actual size.
        /// </param>
        ///
        /// <returns>
        /// true if an image key was specified.
        /// </returns>
        //*************************************************************************
        protected Boolean 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);
        }
 public void TearDown()
 {
     m_oVertexRadiusConverter = null;
 }
 public void SetUp()
 {
     m_oVertexRadiusConverter = new VertexRadiusConverter();
 }
 //*************************************************************************
 //  Constructor: VertexRadiusConverterTest()
 //
 /// <summary>
 /// Initializes a new instance of the <see
 /// cref="VertexRadiusConverterTest" /> class.
 /// </summary>
 //*************************************************************************
 public VertexRadiusConverterTest()
 {
     m_oVertexRadiusConverter = null;
 }