Stores a list of vertex attributes that were edited by .
The list of vertices whose attributes were edited can be obtained from .
Inheritance: Object
    //*************************************************************************
    //  Constructor: AttributesEditedEventArgs()
    //
    /// <summary>
    /// Initializes a new instance of the <see
    /// cref="AttributesEditedEventArgs" /> class.
    /// </summary>
    ///
    /// <param name="edgeIDs">
    /// Array of IDs of the edges whose attributes were edited in the graph, or
    /// null if edge attributes weren't edited.  The IDs came from the edge
    /// worksheet's ID column.
    /// </param>
    ///
    /// <param name="editedEdgeAttributes">
    /// Edge attributes that were applied to the edges, or null if edge
    /// attributes weren't edited.
    /// </param>
    ///
    /// <param name="vertexIDs">
    /// Array of IDs of the vertices whose attributes were edited in the graph,
    /// or null if vertex attributes weren't edited.  The IDs came from the
    /// vertex worksheet's ID column.
    /// </param>
    ///
    /// <param name="editedVertexAttributes">
    /// Vertex attributes that were applied to the vertices, or null if vertex
    /// attributes weren't edited.
    /// </param>
    ///
    /// <remarks>
    /// If edge attributes were edited, <paramref name="edgeIDs" /> and
    /// <paramref name="editedEdgeAttributes" /> should be non-null.  If vertex
    /// attributes were edited, <paramref name="vertexIDs" /> and <paramref
    /// name="editedVertexAttributes" /> should be non-null.
    /// </remarks>
    //*************************************************************************

    public AttributesEditedEventArgs
    (
        Int32 [] edgeIDs,
        EditedEdgeAttributes editedEdgeAttributes,
        Int32 [] vertexIDs,
        EditedVertexAttributes editedVertexAttributes
    )
    {
        m_aiEdgeIDs = edgeIDs;
        m_oEditedEdgeAttributes = editedEdgeAttributes;
        m_aiVertexIDs = vertexIDs;
        m_oEditedVertexAttributes = editedVertexAttributes;

        AssertValid();
    }
Exemple #2
0
        //*************************************************************************
        //  Constructor: AttributesEditedEventArgs()
        //
        /// <summary>
        /// Initializes a new instance of the <see
        /// cref="AttributesEditedEventArgs" /> class.
        /// </summary>
        ///
        /// <param name="edgeIDs">
        /// Array of IDs of the edges whose attributes were edited in the graph, or
        /// null if edge attributes weren't edited.  The IDs came from the edge
        /// worksheet's ID column.
        /// </param>
        ///
        /// <param name="editedEdgeAttributes">
        /// Edge attributes that were applied to the edges, or null if edge
        /// attributes weren't edited.
        /// </param>
        ///
        /// <param name="vertexIDs">
        /// Array of IDs of the vertices whose attributes were edited in the graph,
        /// or null if vertex attributes weren't edited.  The IDs came from the
        /// vertex worksheet's ID column.
        /// </param>
        ///
        /// <param name="editedVertexAttributes">
        /// Vertex attributes that were applied to the vertices, or null if vertex
        /// attributes weren't edited.
        /// </param>
        ///
        /// <remarks>
        /// If edge attributes were edited, <paramref name="edgeIDs" /> and
        /// <paramref name="editedEdgeAttributes" /> should be non-null.  If vertex
        /// attributes were edited, <paramref name="vertexIDs" /> and <paramref
        /// name="editedVertexAttributes" /> should be non-null.
        /// </remarks>
        //*************************************************************************

        public AttributesEditedEventArgs
        (
            Int32 [] edgeIDs,
            EditedEdgeAttributes editedEdgeAttributes,
            Int32 [] vertexIDs,
            EditedVertexAttributes editedVertexAttributes
        )
        {
            m_aiEdgeIDs               = edgeIDs;
            m_oEditedEdgeAttributes   = editedEdgeAttributes;
            m_aiVertexIDs             = vertexIDs;
            m_oEditedVertexAttributes = editedVertexAttributes;

            AssertValid();
        }
    LockButton_Click
    (
        object sender, 
        EventArgs e
    )
    {
        AssertValid();

        ICollection<IVertex> oSelectedVertices =
            oNodeXLControl.SelectedVertices;

        if (oSelectedVertices.Count == 0)
        {
            return;
        }

        // Lock or unlock the vertices.

        Boolean bLockVertices = (sender == tsbLockVertices);

        foreach (IVertex oVertex in oSelectedVertices)
        {
            if (bLockVertices)
            {
                oVertex.SetValue(ReservedMetadataKeys.LockVertexLocation,
                    true);
            }
            else
            {
                oVertex.RemoveKey(ReservedMetadataKeys.LockVertexLocation);
            }
        }

        // Lock or unlock the vertices in the workbook.

        EditedVertexAttributes oEditedVertexAttributes =
            new EditedVertexAttributes();

        oEditedVertexAttributes.Locked = bLockVertices;

        FireAttributesEditedInGraph(null, oEditedVertexAttributes);
    }
    FireAttributesEditedInGraph
    (
        EditedEdgeAttributes oEditedEdgeAttributes,
        EditedVertexAttributes oEditedVertexAttributes
    )
    {
        AssertValid();

        EventHandler<AttributesEditedEventArgs> oAttributesEditedInGraph =
            this.AttributesEditedInGraph;

        if (oAttributesEditedInGraph != null)
        {
            oAttributesEditedInGraph( this,

                new AttributesEditedEventArgs(

                    (oEditedEdgeAttributes == null) ? null :

                        NodeXLControlUtil.GetSelectedEdgeRowIDs(
                            oNodeXLControl).ToArray(),

                    oEditedEdgeAttributes,

                    (oEditedVertexAttributes == null) ? null :

                        NodeXLControlUtil.GetSelectedVertexRowIDs(
                            oNodeXLControl).ToArray(),

                    oEditedVertexAttributes
                ) );
        }
    }
Exemple #5
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;
        }
        GetInitialVertexAttributes()
        {
            // AssertValid();

            EditedVertexAttributes oInitialVertexAttributes =
                new EditedVertexAttributes();

            ICollection <IMetadataProvider> oSelectedVertices =
                (ICollection <IMetadataProvider>)m_oNodeXLControl.SelectedVertices;

            // Color.

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

            // Shape.

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

            // Radius.

            oInitialVertexAttributes.Radius = GetInitialSingleAttributeValue(
                oSelectedVertices, ReservedMetadataKeys.PerVertexRadius,
                new VertexRadiusConverter());

            // Alpha.

            oInitialVertexAttributes.Alpha = GetInitialSingleAttributeValue(
                oSelectedVertices, ReservedMetadataKeys.PerAlpha,
                new AlphaConverter());

            // Visibility.

            oInitialVertexAttributes.Visibility = null;

            // Label.

            oInitialVertexAttributes.Label = GetInitialClassAttributeValue <String>(
                oSelectedVertices, ReservedMetadataKeys.PerVertexLabel);

            // Label fill color.

            oInitialVertexAttributes.LabelFillColor =
                GetInitialStructAttributeValue <Color>(
                    ReservedMetadataKeys.PerVertexLabelFillColor);

            // Label position.

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

            // Tooltip.

            oInitialVertexAttributes.ToolTip =
                GetInitialClassAttributeValue <String>(oSelectedVertices,
                                                       ReservedMetadataKeys.PerVertexToolTip);

            // Locked.

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

            // Marked.

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

            return(oInitialVertexAttributes);
        }