//*************************************************************************
        //  Constructor: VertexAttributesEditedEventArgs()
        //
        /// <summary>
        /// Initializes a new instance of the <see
        /// cref="VertexAttributesEditedEventArgs" /> class.
        /// </summary>
        ///
        /// <param name="vertexIDs">
        /// Array of IDs of the vertices whose attributes were edited in the graph.
        /// The IDs came from the vertex worksheet's ID column.  Can be empty but
        /// not null.
        /// </param>
        ///
        /// <param name="editedVertexAttributes">
        /// Vertex attributes that were applied to the vertices.
        /// </param>
        //*************************************************************************
        public VertexAttributesEditedEventArgs(
            Int32 [] vertexIDs,
            EditedVertexAttributes editedVertexAttributes
            )
        {
            m_aiVertexIDs = vertexIDs;
            m_oEditedVertexAttributes = editedVertexAttributes;

            AssertValid();
        }
        //*************************************************************************
        //  Constructor: VertexAttributesEditedEventArgs()
        //
        /// <summary>
        /// Initializes a new instance of the <see
        /// cref="VertexAttributesEditedEventArgs" /> class.
        /// </summary>
        ///
        /// <param name="vertexIDs">
        /// Array of IDs of the vertices whose attributes were edited in the graph.
        /// The IDs came from the vertex worksheet's ID column.  Can be empty but
        /// not null.
        /// </param>
        ///
        /// <param name="editedVertexAttributes">
        /// Vertex attributes that were applied to the vertices.
        /// </param>
        //*************************************************************************

        public VertexAttributesEditedEventArgs
        (
            Int32 [] vertexIDs,
            EditedVertexAttributes editedVertexAttributes
        )
        {
            m_aiVertexIDs             = vertexIDs;
            m_oEditedVertexAttributes = editedVertexAttributes;

            AssertValid();
        }
示例#3
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);
        }
示例#4
0
文件: Sheet2.cs 项目: yesbb12/NetMap
        OnVertexAttributesEditedInGraph
        (
            VertexAttributesEditedEventArgs e
        )
        {
            Debug.Assert(e != null);
            AssertValid();

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

            // Get a dictionary containing the ID of each row in the table.

            Dictionary <Int32, Int32> oRowIDDictionary;

            if (!m_oSheets1And2Helper.TryGetAllRowIDs(out oRowIDDictionary))
            {
                // Nothing can be done without the IDs.

                return;
            }

            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, oLabelPositionColumnData, oLockedColumnData,
                                                 oMarkedColumnData;

            Object [,] aoColorValues         = null;
            Object [,] aoShapeValues         = null;
            Object [,] aoRadiusValues        = null;
            Object [,] aoAlphaValues         = null;
            Object [,] aoVisibilityValues    = null;
            Object [,] aoLabelPositionValues = null;
            Object [,] aoLockedValues        = null;
            Object [,] aoMarkedValues        = null;

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.Color, out oColorColumnData,
                                                     out aoColorValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.Shape, out oShapeColumnData,
                                                     out aoShapeValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.Radius, out oRadiusColumnData,
                                                     out aoRadiusValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     CommonTableColumnNames.Alpha, out oAlphaColumnData,
                                                     out aoAlphaValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     CommonTableColumnNames.Visibility, out oVisibilityColumnData,
                                                     out aoVisibilityValues);

            ExcelUtil.TryGetTableColumnDataAndValues(oVertexTable,
                                                     VertexTableColumnNames.LabelPosition, out oLabelPositionColumnData,
                                                     out aoLabelPositionValues);

            ExcelUtil.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 (oEditedVertexAttributes.LabelPosition.HasValue &&
                    aoLabelPositionValues != null)
                {
                    aoLabelPositionValues[iRowOneBased, 1] =
                        oVertexLabelPositionConverter.GraphToWorkbook(
                            oEditedVertexAttributes.LabelPosition.Value);
                }

                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 =
                GetExcelActiveWorksheetRestorer();

            ExcelActiveWorksheetState oExcelActiveWorksheetState =
                oExcelActiveWorksheetRestorer.ActivateWorksheet(this.InnerObject);

            try
            {
                if (aoColorValues != null)
                {
                    oColorColumnData.set_Value(Missing.Value, aoColorValues);
                }

                if (aoShapeValues != null)
                {
                    oShapeColumnData.set_Value(Missing.Value, aoShapeValues);
                }

                if (aoRadiusValues != null)
                {
                    oRadiusColumnData.set_Value(Missing.Value, aoRadiusValues);
                }

                if (aoAlphaValues != null)
                {
                    oAlphaColumnData.set_Value(Missing.Value, aoAlphaValues);
                }

                if (aoVisibilityValues != null)
                {
                    oVisibilityColumnData.set_Value(Missing.Value,
                                                    aoVisibilityValues);
                }

                if (aoLabelPositionValues != null)
                {
                    oLabelPositionColumnData.set_Value(Missing.Value,
                                                       aoLabelPositionValues);
                }

                if (aoLockedValues != null)
                {
                    oLockedColumnData.set_Value(Missing.Value, aoLockedValues);
                }

                if (aoMarkedValues != null)
                {
                    oMarkedColumnData.set_Value(Missing.Value, aoMarkedValues);
                }
            }
            finally
            {
                oExcelActiveWorksheetRestorer.Restore(oExcelActiveWorksheetState);
            }

            Globals.ThisWorkbook.ShowWaitCursor = false;
        }