Пример #1
0
        ThisWorkbook_GraphLaidOut
        (
            Object sender,
            GraphLaidOutEventArgs e
        )
        {
            Debug.Assert(e != null);
            AssertValid();

            if (m_oSheets1And2Helper.TableExists)
            {
                OnGraphLaidOut(e);
            }
        }
Пример #2
0
        //*************************************************************************
        //  Method: ThisWorkbook_GraphLaidOut()
        //
        /// <summary>
        /// Handles the GraphLaidOut event on ThisWorkbook.
        /// </summary>
        ///
        /// <param name="sender">
        /// Standard event argument.
        /// </param>
        ///
        /// <param name="e">
        /// Standard event argument.
        /// </param>
        ///
        /// <remarks>
        /// Graph layout occurs asynchronously.  This event fires when the graph
        /// is successfully laid out.
        /// </remarks>
        //*************************************************************************
        private void ThisWorkbook_GraphLaidOut(
            Object sender,
            GraphLaidOutEventArgs e
            )
        {
            Debug.Assert(e != null);
            AssertValid();

            if (m_oSheets1And2Helper.TableExists)
            {
            OnGraphLaidOut(e);
            }
        }
Пример #3
0
        //*************************************************************************
        //  Method: OnGraphLaidOut()
        //
        /// <summary>
        /// Handles the GraphLaidOut event on ThisWorkbook.
        /// </summary>
        ///
        /// <param name="e">
        /// Standard event argument.
        /// </param>
        ///
        /// <param name="oVertexTable">
        /// Vertex table.
        /// </param>
        ///
        /// <param name="oDataBodyRange">
        /// Data body range within the vertex table.
        /// </param>
        ///
        /// <param name="oVisibleDataBodyRange">
        /// Visible data body range, which may contain multiple areas.
        /// </param>
        ///
        /// <param name="oIDColumnData">
        /// ID column data from the vertex table.  This excludes the header.
        /// </param>
        ///
        /// <param name="oXColumn">
        /// X-coordinate column from the vertex table.  This is the entire column,
        /// including the header.
        /// </param>
        ///
        /// <param name="oYColumn">
        /// Y-coordinate column from the vertex table.  This is the entire column,
        /// including the header.
        /// </param>
        //*************************************************************************
        private void OnGraphLaidOut(
            GraphLaidOutEventArgs e,
            Microsoft.Office.Interop.Excel.ListObject oVertexTable,
            Microsoft.Office.Interop.Excel.Range oDataBodyRange,
            Microsoft.Office.Interop.Excel.Range oVisibleDataBodyRange,
            Microsoft.Office.Interop.Excel.Range oIDColumnData,
            Microsoft.Office.Interop.Excel.ListColumn oXColumn,
            Microsoft.Office.Interop.Excel.ListColumn oYColumn
            )
        {
            Debug.Assert(e != null);
            Debug.Assert(oVertexTable != null);
            Debug.Assert(oDataBodyRange != null);
            Debug.Assert(oVisibleDataBodyRange != null);
            Debug.Assert(oIDColumnData != null);
            Debug.Assert(oXColumn != null);
            Debug.Assert(oYColumn != null);
            AssertValid();

            // Read the ID column.

            Object [,] aoIDValues = ExcelUtil.GetRangeValues(oIDColumnData);

            // Read the lock column if it's available.  This excludes the header.
            // (Locked vertices should not have their locations changed.)

            Microsoft.Office.Interop.Excel.Range oLockedColumnData;
            Object [,] aoLockedValues = null;

            if ( ExcelUtil.TryGetTableColumnData(oVertexTable,
            VertexTableColumnNames.Locked, out oLockedColumnData) )
            {
            aoLockedValues = ExcelUtil.GetRangeValues(oLockedColumnData);
            }

            Int32 iDataBodyRangeRow = oDataBodyRange.Row;

            Int32 iXColumnOneBased = oXColumn.Range.Column;
            Int32 iYColumnOneBased = oYColumn.Range.Column;

            // Create an object that converts a vertex location between coordinates
            // used in the NodeXL graph and coordinates used in the worksheet.

            VertexLocationConverter oVertexLocationConverter =
            new VertexLocationConverter(e.GraphRectangle);

            // Loop through the areas in the visible range.

            foreach (Microsoft.Office.Interop.Excel.Range oVisibleDataArea in
            oVisibleDataBodyRange.Areas)
            {
            // Get the row numbers for the ID and lock columns.  (These are
            // with respect to the ID and lock values.)

            Int32 iFirstIDRowOneBased =
                oVisibleDataArea.Row - iDataBodyRangeRow + 1;

            Int32 iLastIDRowOneBased =
                iFirstIDRowOneBased + oVisibleDataArea.Rows.Count - 1;

            Int32 iRows = iLastIDRowOneBased - iFirstIDRowOneBased + 1;

            // Get the row numbers for the location values within the visible
            // area.  (These are with respect to the worksheet.)

            Int32 iFirstXYRowOneBased = oVisibleDataArea.Row;
            Int32 iLastXYRowOneBased = iFirstXYRowOneBased + iRows - 1;

            // Read the old location formulas within the visible area.  (To
            // avoid overwriting locked X,Y values that are formulas, read
            // formulas and not values.)

            Microsoft.Office.Interop.Excel.Range oXRange = this.get_Range(
                this.Cells[iFirstXYRowOneBased, iXColumnOneBased],
                this.Cells[iLastXYRowOneBased, iXColumnOneBased]
                );

            Microsoft.Office.Interop.Excel.Range oYRange = this.get_Range(
                this.Cells[iFirstXYRowOneBased, iYColumnOneBased],
                this.Cells[iLastXYRowOneBased, iYColumnOneBased]
                );

            Object [,] aoXFormulas = ExcelUtil.GetRangeFormulas(oXRange);
            Object [,] aoYFormulas = ExcelUtil.GetRangeFormulas(oYRange);

            for (Int32 iIDRowOneBased = iFirstIDRowOneBased;
                iIDRowOneBased <= iLastIDRowOneBased; iIDRowOneBased++)
            {
                if ( aoLockedValues != null &&
                    VertexIsLocked(aoLockedValues, iIDRowOneBased) )
                {
                    // The old location shouldn't be changed.

                    continue;
                }

                // Get this row's ID.

                Int32 iID;

                if ( !m_oSheets1And2Helper.TryGetRowID(
                    aoIDValues, iIDRowOneBased, out iID) )
                {
                    // The user may have added a row since the workbook was
                    // read into the graph.  Ignore this row.

                    continue;
                }

                // Get the vertex object corresponding to the ID.

                IIdentityProvider oVertex;

                if ( !e.VertexIDDictionary.TryGetValue(iID, out oVertex) )
                {
                    continue;
                }

                // Convert the vertex location to workbook coordinates.

                Single fWorkbookX, fWorkbookY;

                Debug.Assert(oVertex is IVertex);

                oVertexLocationConverter.GraphToWorkbook(
                    ( (IVertex)oVertex ).Location,
                    out fWorkbookX, out fWorkbookY);

                // Store the vertex locations in the arrays.

                Int32 iXYFormulasRowOneBased =
                    iIDRowOneBased - iFirstIDRowOneBased + 1;

                aoXFormulas[iXYFormulasRowOneBased, 1] = fWorkbookX;
                aoYFormulas[iXYFormulasRowOneBased, 1] = fWorkbookY;
            }

            // Set the new vertex locations in the worksheet.

            oXRange.Formula = aoXFormulas;
            oYRange.Formula = aoYFormulas;
            }
        }
Пример #4
0
        //*************************************************************************
        //  Method: OnGraphLaidOut()
        //
        /// <summary>
        /// Handles the GraphLaidOut event on ThisWorkbook.
        /// </summary>
        ///
        /// <param name="e">
        /// Standard event argument.
        /// </param>
        ///
        /// <remarks>
        /// Graph layout occurs asynchronously.  This event fires when the graph
        /// is successfully laid out.
        /// </remarks>
        //*************************************************************************
        private void OnGraphLaidOut(
            GraphLaidOutEventArgs e
            )
        {
            Debug.Assert(e != null);
            AssertValid();

            // This method gathers some necessary information and returns without
            // doing anything else if some of the information is missing.

            Microsoft.Office.Interop.Excel.ListObject oVertexTable =
            Vertices.InnerObject;

            // Get the ID column data from the vertex table.  This excludes the
            // header.

            Microsoft.Office.Interop.Excel.Range oIDColumnData;

            if ( !ExcelUtil.TryGetTableColumnData(oVertexTable,
            CommonTableColumnNames.ID, out oIDColumnData) )
            {
            return;
            }

            // Get the location columns from the vertex table.  These are the
            // entire table columns, including the headers.

            Microsoft.Office.Interop.Excel.ListColumn oXColumn, oYColumn;

            if (
            !ExcelUtil.TryGetTableColumn(oVertexTable,
                VertexTableColumnNames.X, out oXColumn)
            ||
            !ExcelUtil.TryGetTableColumn(oVertexTable,
                VertexTableColumnNames.Y, out oYColumn)
            )
            {
            return;
            }

            // The vertex table may be filtered.  Get the visible range, which may
            // contain multiple areas.

            Microsoft.Office.Interop.Excel.Range oDataBodyRange =
            Vertices.DataBodyRange;

            if (oDataBodyRange == null)
            {
            return;
            }

            Microsoft.Office.Interop.Excel.Range oVisibleDataBodyRange;

            if ( !ExcelUtil.TryGetVisibleRange(oDataBodyRange,
            out oVisibleDataBodyRange) )
            {
            return;
            }

            // The necessary information has been gathered.  Move on to the actual
            // work.  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
            {
            OnGraphLaidOut(e, oVertexTable, oDataBodyRange,
                oVisibleDataBodyRange, oIDColumnData, oXColumn, oYColumn);
            }
            finally
            {
            oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }
        }
Пример #5
0
        OnGraphLaidOut
        (
            GraphLaidOutEventArgs e
        )
        {
            Debug.Assert(e != null);
            AssertValid();

            // This method gathers some necessary information and returns without
            // doing anything else if some of the information is missing.

            Microsoft.Office.Interop.Excel.ListObject oVertexTable =
                Vertices.InnerObject;

            // Get the ID column data from the vertex table.  This excludes the
            // header.

            Microsoft.Office.Interop.Excel.Range oIDColumnData;

            if (!ExcelUtil.TryGetTableColumnData(oVertexTable,
                                                 CommonTableColumnNames.ID, out oIDColumnData))
            {
                return;
            }

            // Get the location columns from the vertex table.  These are the
            // entire table columns, including the headers.

            Microsoft.Office.Interop.Excel.ListColumn oXColumn, oYColumn;

            if (
                !ExcelUtil.TryGetTableColumn(oVertexTable,
                                             VertexTableColumnNames.X, out oXColumn)
                ||
                !ExcelUtil.TryGetTableColumn(oVertexTable,
                                             VertexTableColumnNames.Y, out oYColumn)
                )
            {
                return;
            }

            // The vertex table may be filtered.  Get the visible range, which may
            // contain multiple areas.

            Microsoft.Office.Interop.Excel.Range oDataBodyRange =
                Vertices.DataBodyRange;

            if (oDataBodyRange == null)
            {
                return;
            }

            Microsoft.Office.Interop.Excel.Range oVisibleDataBodyRange;

            if (!ExcelUtil.TryGetVisibleRange(oDataBodyRange,
                                              out oVisibleDataBodyRange))
            {
                return;
            }

            // The necessary information has been gathered.  Move on to the actual
            // work.  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
            {
                OnGraphLaidOut(e, oVertexTable, oDataBodyRange,
                               oVisibleDataBodyRange, oIDColumnData, oXColumn, oYColumn);
            }
            finally
            {
                oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }
        }
Пример #6
0
        OnGraphLaidOut
        (
            GraphLaidOutEventArgs e,
            Microsoft.Office.Interop.Excel.ListObject oVertexTable,
            Microsoft.Office.Interop.Excel.Range oDataBodyRange,
            Microsoft.Office.Interop.Excel.Range oVisibleDataBodyRange,
            Microsoft.Office.Interop.Excel.Range oIDColumnData,
            Microsoft.Office.Interop.Excel.ListColumn oXColumn,
            Microsoft.Office.Interop.Excel.ListColumn oYColumn
        )
        {
            Debug.Assert(e != null);
            Debug.Assert(oVertexTable != null);
            Debug.Assert(oDataBodyRange != null);
            Debug.Assert(oVisibleDataBodyRange != null);
            Debug.Assert(oIDColumnData != null);
            Debug.Assert(oXColumn != null);
            Debug.Assert(oYColumn != null);
            AssertValid();

            // Read the ID column.

            Object [,] aoIDValues = ExcelUtil.GetRangeValues(oIDColumnData);

            // Read the lock column if it's available.  This excludes the header.
            // (Locked vertices should not have their locations changed.)

            Microsoft.Office.Interop.Excel.Range oLockedColumnData;
            Object [,] aoLockedValues = null;

            if (ExcelUtil.TryGetTableColumnData(oVertexTable,
                                                VertexTableColumnNames.Locked, out oLockedColumnData))
            {
                aoLockedValues = ExcelUtil.GetRangeValues(oLockedColumnData);
            }

            Int32 iDataBodyRangeRow = oDataBodyRange.Row;

            Int32 iXColumnOneBased = oXColumn.Range.Column;
            Int32 iYColumnOneBased = oYColumn.Range.Column;

            // Create an object that converts a vertex location between coordinates
            // used in the NodeXL graph and coordinates used in the worksheet.

            VertexLocationConverter oVertexLocationConverter =
                new VertexLocationConverter(e.GraphRectangle);

            // Loop through the areas in the visible range.

            foreach (Microsoft.Office.Interop.Excel.Range oVisibleDataArea in
                     oVisibleDataBodyRange.Areas)
            {
                // Get the row numbers for the ID and lock columns.  (These are
                // with respect to the ID and lock values.)

                Int32 iFirstIDRowOneBased =
                    oVisibleDataArea.Row - iDataBodyRangeRow + 1;

                Int32 iLastIDRowOneBased =
                    iFirstIDRowOneBased + oVisibleDataArea.Rows.Count - 1;

                Int32 iRows = iLastIDRowOneBased - iFirstIDRowOneBased + 1;

                // Get the row numbers for the location values within the visible
                // area.  (These are with respect to the worksheet.)

                Int32 iFirstXYRowOneBased = oVisibleDataArea.Row;
                Int32 iLastXYRowOneBased  = iFirstXYRowOneBased + iRows - 1;

                // Read the old location formulas within the visible area.  (To
                // avoid overwriting locked X,Y values that are formulas, read
                // formulas and not values.)

                Microsoft.Office.Interop.Excel.Range oXRange = this.get_Range(
                    this.Cells[iFirstXYRowOneBased, iXColumnOneBased],
                    this.Cells[iLastXYRowOneBased, iXColumnOneBased]
                    );

                Microsoft.Office.Interop.Excel.Range oYRange = this.get_Range(
                    this.Cells[iFirstXYRowOneBased, iYColumnOneBased],
                    this.Cells[iLastXYRowOneBased, iYColumnOneBased]
                    );

                Object [,] aoXFormulas = ExcelUtil.GetRangeFormulas(oXRange);
                Object [,] aoYFormulas = ExcelUtil.GetRangeFormulas(oYRange);

                for (Int32 iIDRowOneBased = iFirstIDRowOneBased;
                     iIDRowOneBased <= iLastIDRowOneBased; iIDRowOneBased++)
                {
                    if (aoLockedValues != null &&
                        VertexIsLocked(aoLockedValues, iIDRowOneBased))
                    {
                        // The old location shouldn't be changed.

                        continue;
                    }

                    // Get this row's ID.

                    Int32 iID;

                    if (!m_oSheets1And2Helper.TryGetRowID(
                            aoIDValues, iIDRowOneBased, out iID))
                    {
                        // The user may have added a row since the workbook was
                        // read into the graph.  Ignore this row.

                        continue;
                    }

                    // Get the vertex object corresponding to the ID.

                    IIdentityProvider oVertex;

                    if (!e.VertexIDDictionary.TryGetValue(iID, out oVertex))
                    {
                        continue;
                    }

                    // Convert the vertex location to workbook coordinates.

                    Single fWorkbookX, fWorkbookY;

                    Debug.Assert(oVertex is IVertex);

                    oVertexLocationConverter.GraphToWorkbook(
                        ((IVertex)oVertex).Location,
                        out fWorkbookX, out fWorkbookY);

                    // Store the vertex locations in the arrays.

                    Int32 iXYFormulasRowOneBased =
                        iIDRowOneBased - iFirstIDRowOneBased + 1;

                    aoXFormulas[iXYFormulasRowOneBased, 1] = fWorkbookX;
                    aoYFormulas[iXYFormulasRowOneBased, 1] = fWorkbookY;
                }

                // Set the new vertex locations in the worksheet.

                oXRange.Formula = aoXFormulas;
                oYRange.Formula = aoYFormulas;
            }
        }
Пример #7
0
        //*************************************************************************
        //  Method: TaskPane_GraphLaidOut()
        //
        /// <summary>
        /// Handles the GraphLaidOut event on the TaskPane.
        /// </summary>
        ///
        /// <param name="sender">
        /// Standard event argument.
        /// </param>
        ///
        /// <param name="e">
        /// Standard event argument.
        /// </param>
        ///
        /// <remarks>
        /// Graph layout occurs asynchronously.  This event fires when the graph
        /// is successfully laid out.
        /// </remarks>
        //*************************************************************************
        private void TaskPane_GraphLaidOut(
            Object sender,
            GraphLaidOutEventArgs e
            )
        {
            Debug.Assert(e != null);
            AssertValid();

            if ( !this.ExcelApplicationIsReady(false) )
            {
            return;
            }

            // Forward the event.

            GraphLaidOutEventHandler oGraphLaidOut = this.GraphLaidOut;

            if (oGraphLaidOut != null)
            {
            try
            {
                oGraphLaidOut(this, e);
            }
            catch (Exception oException)
            {
                ErrorUtil.OnException(oException);
            }
            }
        }