예제 #1
0
        ReadLocation
        (
            ExcelTableReader.ExcelTableRow oRow,
            VertexLocationConverter oVertexLocationConverter,
            IVertex oVertex
        )
        {
            Debug.Assert(oRow != null);
            Debug.Assert(oVertexLocationConverter != null);
            Debug.Assert(oVertex != null);
            AssertValid();

            String sX;

            Boolean bHasX = oRow.TryGetNonEmptyStringFromCell(
                VertexTableColumnNames.X, out sX);

            String sY;

            Boolean bHasY = oRow.TryGetNonEmptyStringFromCell(
                VertexTableColumnNames.Y, out sY);

            if (bHasX != bHasY)
            {
                // X or Y alone won't do.

                goto Error;
            }

            if (!bHasX && !bHasY)
            {
                return(false);
            }

            Single fX, fY;

            if (!Single.TryParse(sX, out fX) || !Single.TryParse(sY, out fY))
            {
                goto Error;
            }

            // Transform the location from workbook coordinates to graph
            // coordinates.

            oVertex.Location = oVertexLocationConverter.WorkbookToGraph(fX, fY);

            return(true);

Error:

            Range oInvalidCell = oRow.GetRangeForCell(
                VertexTableColumnNames.X);

            OnWorkbookFormatError(String.Format(

                                      "There is a problem with the vertex location at {0}.  If you"
                                      + " enter a vertex location, it must include both X and Y"
                                      + " numbers.  Any numbers are acceptable, although {1} is used"
                                      + " for any number less than {1} and and {2} is used for any"
                                      + " number greater than {2}."
                                      ,
                                      ExcelUtil.GetRangeAddress(oInvalidCell),

                                      VertexLocationConverter.MinimumXYWorkbook.ToString(
                                          ExcelTemplateForm.Int32Format),

                                      VertexLocationConverter.MaximumXYWorkbook.ToString(
                                          ExcelTemplateForm.Int32Format)
                                      ),

                                  oInvalidCell
                                  );

            // Make the compiler happy.

            return(false);
        }
        public void TestWorkbookToGraph4()
        {
            // Empty rectangle.

            m_oVertexLocationConverter = new VertexLocationConverter(
            Rectangle.FromLTRB(100, 200, 100, 200) );

            Single WorkbookX = VertexLocationConverter.MaximumXYWorkbook;
            Single WorkbookY = VertexLocationConverter.MaximumXYWorkbook;
            Single ExpectedGraphX = 100;
            Single ExpectedGraphY = 200;

            PointF oGraphPointF = m_oVertexLocationConverter.WorkbookToGraph(
            WorkbookX, WorkbookY);

            Assert.AreEqual(ExpectedGraphX, oGraphPointF.X);
            Assert.AreEqual(ExpectedGraphY, oGraphPointF.Y);
        }
예제 #3
0
        //*************************************************************************
        //  Method: ReadLocation()
        //
        /// <summary>
        /// If a location has been specified for a vertex, sets the vertex's
        /// location.
        /// </summary>
        ///
        /// <param name="oRow">
        /// Row containing the vertex data.
        /// </param>
        ///
        /// <param name="oVertexLocationConverter">
        /// Object that converts a vertex location between coordinates used in the
        /// Excel workbook and coordinates used in the NodeXL graph.
        /// </param>
        ///
        /// <param name="oVertex">
        /// Vertex to set the location on.
        /// </param>
        ///
        /// <returns>
        /// true if a location was specified.
        /// </returns>
        //*************************************************************************
        protected Boolean ReadLocation(
            ExcelTableReader.ExcelTableRow oRow,
            VertexLocationConverter oVertexLocationConverter,
            IVertex oVertex
            )
        {
            Debug.Assert(oRow != null);
            Debug.Assert(oVertexLocationConverter != null);
            Debug.Assert(oVertex != null);
            AssertValid();

            String sX;

            Boolean bHasX = oRow.TryGetNonEmptyStringFromCell(
            VertexTableColumnNames.X, out sX);

            String sY;

            Boolean bHasY = oRow.TryGetNonEmptyStringFromCell(
            VertexTableColumnNames.Y, out sY);

            if (bHasX != bHasY)
            {
            // X or Y alone won't do.

            goto Error;
            }

            if (!bHasX && !bHasY)
            {
            return (false);
            }

            Single fX, fY;

            if ( !Single.TryParse(sX, out fX) || !Single.TryParse(sY, out fY) )
            {
            goto Error;
            }

            // Transform the location from workbook coordinates to graph
            // coordinates.

            oVertex.Location = oVertexLocationConverter.WorkbookToGraph(fX, fY);

            return (true);

            Error:

            Range oInvalidCell = oRow.GetRangeForCell(
                VertexTableColumnNames.X);

            OnWorkbookFormatError( String.Format(

                "There is a problem with the vertex location at {0}.  If you"
                + " enter a vertex location, it must include both X and Y"
                + " numbers.  Any numbers are acceptable, although {1} is used"
                + " for any number less than {1} and and {2} is used for any"
                + " number greater than {2}."
                ,
                ExcelUtil.GetRangeAddress(oInvalidCell),

                VertexLocationConverter.MinimumXYWorkbook.ToString(
                    ExcelTemplateForm.Int32Format),

                VertexLocationConverter.MaximumXYWorkbook.ToString(
                    ExcelTemplateForm.Int32Format)
                ),

                oInvalidCell
                );

            // Make the compiler happy.

            return (false);
        }