Пример #1
0
        GetFilteredVertexIDs
        (
            DynamicFilterDialog oDynamicFilterDialog
        )
        {
            Debug.Assert(oDynamicFilterDialog != null);
            Debug.Assert(oDynamicFilterDialog.Tag is HashSet <Int32>[]);

            return(
                ((HashSet <Int32>[])oDynamicFilterDialog.Tag)[1]
                );
        }
Пример #2
0
        OnEdgeFiltered
        (
            Object oEdge,
            Boolean bMadeVisible,
            DynamicFilterDialog oDynamicFilterDialog
        )
        {
            Debug.Assert(oEdge is IEdge);
            Debug.Assert(oDynamicFilterDialog != null);

            IEdge oEdge2 = (IEdge)oEdge;

            if (bMadeVisible)
            {
                // When an edge is made visible, its vertices should also be made
                // visible.

                IVertex [] aoVertices = oEdge2.Vertices;

                DynamicallyFilterEdgeOrVertex(aoVertices[0], true);
                DynamicallyFilterEdgeOrVertex(aoVertices[1], true);
            }
            else
            {
                // When an edge is filtered, its vertices should not be modified,
                // unless a vertex becomes an isolate due to filtering.  In that
                // case, the vertex should be filtered.

                HashSet <Int32> oFilteredEdgeIDs =
                    GetFilteredEdgeIDs(oDynamicFilterDialog);

                foreach (IVertex oAdjacentVertex in oEdge2.Vertices)
                {
                    // Note that each adjacent vertex always has at least one
                    // incident edge, so special-case code to handle the All()
                    // method's behavior for empty collections is not required
                    // here.

                    if (oAdjacentVertex.IncidentEdges.All(

                            oIncidentEdge => oFilteredEdgeIDs.Contains(
                                oIncidentEdge.ID)
                            ))
                    {
                        DynamicallyFilterEdgeOrVertex(oAdjacentVertex, false);
                    }
                }
            }
        }
Пример #3
0
        ReadFilteredAlpha
        (
            DynamicFilterDialog dynamicFilterDialog,
            NodeXLControl nodeXLControl,
            Boolean forceRedraw
        )
        {
            Debug.Assert(dynamicFilterDialog != null);
            Debug.Assert(nodeXLControl != null);

            nodeXLControl.FilteredAlpha =
                (new AlphaConverter()).WorkbookToGraphAsByte(
                    dynamicFilterDialog.FilteredAlpha);

            if (forceRedraw)
            {
                nodeXLControl.DrawGraph();
            }
        }
Пример #4
0
        OnVertexFiltered
        (
            Object oVertex,
            Boolean bMadeVisible,
            DynamicFilterDialog oDynamicFilterDialog
        )
        {
            Debug.Assert(oVertex != null);
            Debug.Assert(oDynamicFilterDialog != null);

            // When a vertex is filtered, its incident edges should also be
            // filtered.  When a vertex is made visible, its incident edges should
            // also be made visible, unless 1) the edge was filtered by an edge
            // filter; or 2) the adjacent vertex was filtered by a vertex filter.

            HashSet <Int32> oFilteredEdgeIDs =
                GetFilteredEdgeIDs(oDynamicFilterDialog);

            HashSet <Int32> oFilteredVertexIDs =
                GetFilteredVertexIDs(oDynamicFilterDialog);

            Debug.Assert(oVertex is IVertex);

            IVertex oVertex2 = (IVertex)oVertex;

            foreach (IEdge oEdge in oVertex2.IncidentEdges)
            {
                if (bMadeVisible)
                {
                    if (
                        oFilteredEdgeIDs.Contains(oEdge.ID)
                        ||
                        oFilteredVertexIDs.Contains(
                            oEdge.GetAdjacentVertex(oVertex2).ID)
                        )
                    {
                        continue;
                    }
                }

                DynamicallyFilterEdgeOrVertex(oEdge, bMadeVisible);
            }
        }
Пример #5
0
        ReadVertexDynamicFilterColumn
        (
            DynamicFilterDialog oDynamicFilterDialog,
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            NodeXLControl oNodeXLControl,
            Boolean bForceRedraw,
            Dictionary <Int32, IIdentityProvider> oVertexRowIDDictionary
        )
        {
            Debug.Assert(oDynamicFilterDialog != null);
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oNodeXLControl != null);
            Debug.Assert(oVertexRowIDDictionary != null);

            ReadDynamicFilterColumn(oDynamicFilterDialog, oWorkbook,
                                    oNodeXLControl, WorksheetNames.Vertices, TableNames.Vertices,
                                    oVertexRowIDDictionary, GetFilteredVertexIDs(oDynamicFilterDialog),
                                    VertexCanBeMadeVisible, OnVertexFiltered, bForceRedraw);
        }
Пример #6
0
        ReadDynamicFilterColumns
        (
            DynamicFilterDialog dynamicFilterDialog,
            Microsoft.Office.Interop.Excel.Workbook workbook,
            NodeXLControl nodeXLControl,
            Boolean forceRedraw,
            Dictionary <Int32, IIdentityProvider> oEdgeRowIDDictionary,
            Dictionary <Int32, IIdentityProvider> oVertexRowIDDictionary
        )
        {
            Debug.Assert(dynamicFilterDialog != null);
            Debug.Assert(workbook != null);
            Debug.Assert(nodeXLControl != null);
            Debug.Assert(oEdgeRowIDDictionary != null);
            Debug.Assert(oVertexRowIDDictionary != null);

            ReadEdgeDynamicFilterColumn(dynamicFilterDialog, workbook,
                                        nodeXLControl, false, oEdgeRowIDDictionary);

            ReadVertexDynamicFilterColumn(dynamicFilterDialog, workbook,
                                          nodeXLControl, forceRedraw, oVertexRowIDDictionary);
        }
    OnDynamicFilterColumnsChanged
    (
        DynamicFilterDialog dynamicFilterDialog,
        DynamicFilterColumnsChangedEventArgs e,
        Microsoft.Office.Interop.Excel.Workbook workbook,
        NodeXLControl nodeXLControl,
        Dictionary<Int32, IIdentityProvider> edgeRowIDDictionary,
        Dictionary<Int32, IIdentityProvider> vertexRowIDDictionary
    )
    {
        Debug.Assert(dynamicFilterDialog != null);
        Debug.Assert(e != null);
        Debug.Assert(workbook != null);
        Debug.Assert(nodeXLControl != null);
        Debug.Assert(edgeRowIDDictionary != null);
        Debug.Assert(vertexRowIDDictionary != null);

        if (e.DynamicFilterColumns ==
            (DynamicFilterColumns.EdgeTable | DynamicFilterColumns.VertexTable)
            )
        {
            ReadDynamicFilterColumns(dynamicFilterDialog, workbook,
                nodeXLControl, true, edgeRowIDDictionary, vertexRowIDDictionary
                );
        }
        else if (e.DynamicFilterColumns == DynamicFilterColumns.EdgeTable)
        {
            ReadEdgeDynamicFilterColumn(dynamicFilterDialog, workbook,
                nodeXLControl, true, edgeRowIDDictionary);
        }
        else if (e.DynamicFilterColumns == DynamicFilterColumns.VertexTable)
        {
            ReadVertexDynamicFilterColumn(dynamicFilterDialog, workbook,
                nodeXLControl, true, vertexRowIDDictionary);
        }
    }
Пример #8
0
        OnDynamicFilterColumnsChanged
        (
            DynamicFilterDialog dynamicFilterDialog,
            DynamicFilterColumnsChangedEventArgs e,
            Microsoft.Office.Interop.Excel.Workbook workbook,
            NodeXLControl nodeXLControl,
            Dictionary <Int32, IIdentityProvider> edgeRowIDDictionary,
            Dictionary <Int32, IIdentityProvider> vertexRowIDDictionary
        )
        {
            Debug.Assert(dynamicFilterDialog != null);
            Debug.Assert(e != null);
            Debug.Assert(workbook != null);
            Debug.Assert(nodeXLControl != null);
            Debug.Assert(edgeRowIDDictionary != null);
            Debug.Assert(vertexRowIDDictionary != null);

            if (e.DynamicFilterColumns ==
                (DynamicFilterColumns.EdgeTable | DynamicFilterColumns.VertexTable)
                )
            {
                ReadDynamicFilterColumns(dynamicFilterDialog, workbook,
                                         nodeXLControl, true, edgeRowIDDictionary, vertexRowIDDictionary
                                         );
            }
            else if (e.DynamicFilterColumns == DynamicFilterColumns.EdgeTable)
            {
                ReadEdgeDynamicFilterColumn(dynamicFilterDialog, workbook,
                                            nodeXLControl, true, edgeRowIDDictionary);
            }
            else if (e.DynamicFilterColumns == DynamicFilterColumns.VertexTable)
            {
                ReadVertexDynamicFilterColumn(dynamicFilterDialog, workbook,
                                              nodeXLControl, true, vertexRowIDDictionary);
            }
        }
    OnVertexFiltered
    (
        Object oVertex,
        Boolean bMadeVisible,
        DynamicFilterDialog oDynamicFilterDialog
    )
    {
        Debug.Assert(oVertex != null);
        Debug.Assert(oDynamicFilterDialog != null);

        // When a vertex is filtered, its incident edges should also be
        // filtered.  When a vertex is made visible, its incident edges should
        // also be made visible, unless 1) the edge was filtered by an edge
        // filter; or 2) the adjacent vertex was filtered by a vertex filter.

        HashSet<Int32> oFilteredEdgeIDs =
            GetFilteredEdgeIDs(oDynamicFilterDialog);

        HashSet<Int32> oFilteredVertexIDs =
            GetFilteredVertexIDs(oDynamicFilterDialog);

        Debug.Assert(oVertex is IVertex);

        IVertex oVertex2 = (IVertex)oVertex;

        foreach (IEdge oEdge in oVertex2.IncidentEdges)
        {
            if (bMadeVisible)
            {
                if (
                    oFilteredEdgeIDs.Contains(oEdge.ID)
                    ||
                    oFilteredVertexIDs.Contains(
                        oEdge.GetAdjacentVertex(oVertex2).ID)
                    )
                {
                    continue;
                }
            }

            DynamicallyFilterEdgeOrVertex(oEdge, bMadeVisible);
        }
    }
    OnEdgeFiltered
    (
        Object oEdge,
        Boolean bMadeVisible,
        DynamicFilterDialog oDynamicFilterDialog
    )
    {
        Debug.Assert(oEdge is IEdge);
        Debug.Assert(oDynamicFilterDialog != null);

        IEdge oEdge2 = (IEdge)oEdge;

        if (bMadeVisible)
        {
            // When an edge is made visible, its vertices should also be made
            // visible.

            IVertex [] aoVertices = oEdge2.Vertices;

            DynamicallyFilterEdgeOrVertex(aoVertices[0], true);
            DynamicallyFilterEdgeOrVertex(aoVertices[1], true);
        }
        else
        {
            // When an edge is filtered, its vertices should not be modified,
            // unless a vertex becomes an isolate due to filtering.  In that
            // case, the vertex should be filtered.

            HashSet<Int32> oFilteredEdgeIDs =
                GetFilteredEdgeIDs(oDynamicFilterDialog);

            foreach (IVertex oAdjacentVertex in oEdge2.Vertices)
            {
                // Note that each adjacent vertex always has at least one
                // incident edge, so special-case code to handle the All()
                // method's behavior for empty collections is not required
                // here.

                if ( oAdjacentVertex.IncidentEdges.All(

                    oIncidentEdge => oFilteredEdgeIDs.Contains(
                        oIncidentEdge.ID)
                    ) )
                {
                    DynamicallyFilterEdgeOrVertex(oAdjacentVertex, false);
                }
            }
        }
    }
    ReadDynamicFilterColumn
    (
        DynamicFilterDialog oDynamicFilterDialog,
        Microsoft.Office.Interop.Excel.Workbook oWorkbook,
        NodeXLControl oNodeXLControl,
        String sWorksheetName,
        String sTableName,
        Dictionary<Int32, IIdentityProvider> oRowIDDictionary,
        HashSet<Int32> oFilteredIDs,
        EdgeOrVertexCanBeMadeVisibleHandler oOnEdgeOrVertexCanBeMadeVisible,
        EdgeOrVertexFilteredHandler oOnEdgeOrVertexFiltered,
        Boolean bForceRedraw
    )
    {
        Debug.Assert(oDynamicFilterDialog != null);
        Debug.Assert(oWorkbook != null);
        Debug.Assert(oNodeXLControl != null);
        Debug.Assert( !String.IsNullOrEmpty(sWorksheetName) );
        Debug.Assert( !String.IsNullOrEmpty(sTableName) );
        Debug.Assert(oRowIDDictionary != null);
        Debug.Assert(oFilteredIDs != null);
        Debug.Assert(oOnEdgeOrVertexCanBeMadeVisible != null);
        Debug.Assert(oOnEdgeOrVertexFiltered != null);

        if (oNodeXLControl.IsLayingOutGraph)
        {
            return;
        }

        oFilteredIDs.Clear();

        // The dynamic filter column on the edge or vertex table contains
        // Booleans indicating whether the edge or vertex should be made
        // visible.

        // Get the data in the ID and dynamic filter columns.

        Object [,] oIDColumnValues, oDynamicFilterColumnValues;

        if ( !TryGetIDAndDynamicFilterValues(oWorkbook, sWorksheetName,
            sTableName, out oIDColumnValues, out oDynamicFilterColumnValues) )
        {
            return;
        }

        HashSet<Int32> oFilteredVertexIDs =
            GetFilteredVertexIDs(oDynamicFilterDialog);

        Int32 iRows = oIDColumnValues.GetUpperBound(0);
        Debug.Assert( iRows == oDynamicFilterColumnValues.GetUpperBound(0) );

        for (Int32 iOneBasedRow = 1; iOneBasedRow <= iRows; iOneBasedRow++)
        {
            Object oID = oIDColumnValues[iOneBasedRow, 1];

            Object oDynamicFilter =
                oDynamicFilterColumnValues[iOneBasedRow, 1];

            IIdentityProvider oEdgeOrVertex;

            if (
                oID is Double
                &&
                oRowIDDictionary.TryGetValue( (Int32)(Double)oID,
                    out oEdgeOrVertex )
                &&
                oDynamicFilter is Boolean
                )
            {
                Debug.Assert(oEdgeOrVertex is IMetadataProvider);

                IMetadataProvider oEdgeOrVertex2 =
                    (IMetadataProvider)oEdgeOrVertex;

                Boolean bMakeVisible = (Boolean)oDynamicFilter;

                if (!bMakeVisible)
                {
                    oFilteredIDs.Add(oEdgeOrVertex.ID);
                }
                else if ( !oOnEdgeOrVertexCanBeMadeVisible(
                    oEdgeOrVertex,
                    GetFilteredEdgeIDs(oDynamicFilterDialog),
                    oFilteredVertexIDs
                    ) )
                {
                    bMakeVisible = false;
                }

                // Filter or make visible the edge or vertex, then call the
                // handler specified by the caller.

                DynamicallyFilterEdgeOrVertex(oEdgeOrVertex2, bMakeVisible);

                oOnEdgeOrVertexFiltered(oEdgeOrVertex2, bMakeVisible,
                    oDynamicFilterDialog);
            }
        }

        if (bForceRedraw)
        {
            oNodeXLControl.DrawGraph();
        }
    }
    ReadVertexDynamicFilterColumn
    (
        DynamicFilterDialog oDynamicFilterDialog,
        Microsoft.Office.Interop.Excel.Workbook oWorkbook,
        NodeXLControl oNodeXLControl,
        Boolean bForceRedraw,
        Dictionary<Int32, IIdentityProvider> oVertexRowIDDictionary
    )
    {
        Debug.Assert(oDynamicFilterDialog != null);
        Debug.Assert(oWorkbook != null);
        Debug.Assert(oNodeXLControl != null);
        Debug.Assert(oVertexRowIDDictionary != null);

        ReadDynamicFilterColumn(oDynamicFilterDialog, oWorkbook,
            oNodeXLControl, WorksheetNames.Vertices, TableNames.Vertices,
            oVertexRowIDDictionary, GetFilteredVertexIDs(oDynamicFilterDialog),
            VertexCanBeMadeVisible, OnVertexFiltered, bForceRedraw);
    }
    ReadFilteredAlpha
    (
        DynamicFilterDialog dynamicFilterDialog,
        NodeXLControl nodeXLControl,
        Boolean forceRedraw
    )
    {
        Debug.Assert(dynamicFilterDialog != null);
        Debug.Assert(nodeXLControl != null);

        nodeXLControl.FilteredAlpha =
            ( new AlphaConverter() ).WorkbookToGraphAsByte(
                dynamicFilterDialog.FilteredAlpha);

        if (forceRedraw)
        {
            nodeXLControl.DrawGraph();
        }
    }
Пример #14
0
        ReadDynamicFilterColumn
        (
            DynamicFilterDialog oDynamicFilterDialog,
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            NodeXLControl oNodeXLControl,
            String sWorksheetName,
            String sTableName,
            Dictionary <Int32, IIdentityProvider> oRowIDDictionary,
            HashSet <Int32> oFilteredIDs,
            EdgeOrVertexCanBeMadeVisibleHandler oOnEdgeOrVertexCanBeMadeVisible,
            EdgeOrVertexFilteredHandler oOnEdgeOrVertexFiltered,
            Boolean bForceRedraw
        )
        {
            Debug.Assert(oDynamicFilterDialog != null);
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oNodeXLControl != null);
            Debug.Assert(!String.IsNullOrEmpty(sWorksheetName));
            Debug.Assert(!String.IsNullOrEmpty(sTableName));
            Debug.Assert(oRowIDDictionary != null);
            Debug.Assert(oFilteredIDs != null);
            Debug.Assert(oOnEdgeOrVertexCanBeMadeVisible != null);
            Debug.Assert(oOnEdgeOrVertexFiltered != null);

            if (oNodeXLControl.IsLayingOutGraph)
            {
                return;
            }

            oFilteredIDs.Clear();

            // The dynamic filter column on the edge or vertex table contains
            // Booleans indicating whether the edge or vertex should be made
            // visible.

            // Get the data in the ID and dynamic filter columns.

            Object [,] oIDColumnValues, oDynamicFilterColumnValues;

            if (!TryGetIDAndDynamicFilterValues(oWorkbook, sWorksheetName,
                                                sTableName, out oIDColumnValues, out oDynamicFilterColumnValues))
            {
                return;
            }

            HashSet <Int32> oFilteredVertexIDs =
                GetFilteredVertexIDs(oDynamicFilterDialog);

            Int32 iRows = oIDColumnValues.GetUpperBound(0);

            Debug.Assert(iRows == oDynamicFilterColumnValues.GetUpperBound(0));

            for (Int32 iOneBasedRow = 1; iOneBasedRow <= iRows; iOneBasedRow++)
            {
                Object oID = oIDColumnValues[iOneBasedRow, 1];

                Object oDynamicFilter =
                    oDynamicFilterColumnValues[iOneBasedRow, 1];

                IIdentityProvider oEdgeOrVertex;

                if (
                    oID is Double
                    &&
                    oRowIDDictionary.TryGetValue((Int32)(Double)oID,
                                                 out oEdgeOrVertex)
                    &&
                    oDynamicFilter is Boolean
                    )
                {
                    Debug.Assert(oEdgeOrVertex is IMetadataProvider);

                    IMetadataProvider oEdgeOrVertex2 =
                        (IMetadataProvider)oEdgeOrVertex;

                    Boolean bMakeVisible = (Boolean)oDynamicFilter;

                    if (!bMakeVisible)
                    {
                        oFilteredIDs.Add(oEdgeOrVertex.ID);
                    }
                    else if (!oOnEdgeOrVertexCanBeMadeVisible(
                                 oEdgeOrVertex,
                                 GetFilteredEdgeIDs(oDynamicFilterDialog),
                                 oFilteredVertexIDs
                                 ))
                    {
                        bMakeVisible = false;
                    }

                    // Filter or make visible the edge or vertex, then call the
                    // handler specified by the caller.

                    DynamicallyFilterEdgeOrVertex(oEdgeOrVertex2, bMakeVisible);

                    oOnEdgeOrVertexFiltered(oEdgeOrVertex2, bMakeVisible,
                                            oDynamicFilterDialog);
                }
            }

            if (bForceRedraw)
            {
                oNodeXLControl.DrawGraph();
            }
        }
    GetFilteredVertexIDs
    (
        DynamicFilterDialog oDynamicFilterDialog
    )
    {
        Debug.Assert(oDynamicFilterDialog != null);
        Debug.Assert( oDynamicFilterDialog.Tag is HashSet<Int32>[] );

        return (
            ( ( HashSet<Int32>[] )oDynamicFilterDialog.Tag )[1]
            );
    }
Пример #16
0
    ShowDynamicFilters()
    {
        AssertValid();

        if (oNodeXLControl.IsLayingOutGraph || !this.NonEmptyWorkbookRead)
        {
            return;
        }

        if (m_oDynamicFilterDialog != null)
        {
            m_oDynamicFilterDialog.Activate();
            return;
        }

        // The dialog is created on demand.

        m_oDynamicFilterDialog = new DynamicFilterDialog(m_oWorkbook);

        Int32 iHwnd = m_oWorkbook.Application.Hwnd;

        m_oDynamicFilterDialog.DynamicFilterColumnsChanged +=
            new DynamicFilterColumnsChangedEventHandler(
                m_oDynamicFilterDialog_DynamicFilterColumnsChanged);

        m_oDynamicFilterDialog.FilteredAlphaChanged +=
            new EventHandler(m_oDynamicFilterDialog_FilteredAlphaChanged);

        m_oDynamicFilterDialog.FormClosed += delegate
        {
            // See the code in ThisWorkbook that opens the
            // AutoFillWorkbookDialog for an explanation of why the
            // SetForegroundWindow() call is necessary.

            Win32Functions.SetForegroundWindow( new IntPtr(iHwnd) );

            m_oDynamicFilterDialog = null;
        };

        // Create a HashSet of edges that have been filtered by edge filters,
        // and a HashSet of vertices that have been filtered by vertex filters.
        //
        // Store the HashSets within the dialog so they are automatically
        // destroyed when the dialog is destroyed.

        m_oDynamicFilterDialog.Tag = new HashSet<Int32> [] {
            new HashSet<Int32>(),
            new HashSet<Int32>()
            };

        m_oDynamicFilterDialog.Show( new Win32Window(iHwnd) );

        // If the dialog throws an exception during initialization,
        // m_oDynamicFilterDialog gets set to null by the FormClosed delegate
        // above.

        if (m_oDynamicFilterDialog != null)
        {
            ReadDynamicFilterColumns(false);

            DynamicFilterHandler.ReadFilteredAlpha(m_oDynamicFilterDialog,
                oNodeXLControl, true);

            UpdateDynamicFiltersLegend();
        }
    }
    ReadDynamicFilterColumns
    (
        DynamicFilterDialog dynamicFilterDialog,
        Microsoft.Office.Interop.Excel.Workbook workbook,
        NodeXLControl nodeXLControl,
        Boolean forceRedraw,
        Dictionary<Int32, IIdentityProvider> oEdgeRowIDDictionary,
        Dictionary<Int32, IIdentityProvider> oVertexRowIDDictionary
    )
    {
        Debug.Assert(dynamicFilterDialog != null);
        Debug.Assert(workbook != null);
        Debug.Assert(nodeXLControl != null);
        Debug.Assert(oEdgeRowIDDictionary != null);
        Debug.Assert(oVertexRowIDDictionary != null);

        ReadEdgeDynamicFilterColumn(dynamicFilterDialog, workbook,
            nodeXLControl, false, oEdgeRowIDDictionary);

        ReadVertexDynamicFilterColumn(dynamicFilterDialog, workbook,
            nodeXLControl, forceRedraw, oVertexRowIDDictionary);
    }