コード例 #1
0
        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);
        }
コード例 #2
0
        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;
        }