Exemple #1
0
        private void UpdateHighlights()
        {
            ClearHighlights();

            // get the selected shape
            NShape shape = (view.Selection.AnchorNode as NShape);

            if (shape == null)
            {
                document.SmartRefreshAllViews();
                return;
            }

            // get the graph in which the shape resides
            NGraphBuilder graphBuilder = new NGraphBuilder(new NShapeGraphAdapter(), new NGraphPartFactory());

            NObjectGraphPartMap map;
            NGraph graph = graphBuilder.BuildGraph(shape, out map);

            if (graph == null)
            {
                document.SmartRefreshAllViews();
                return;
            }

            // get the vertex which represents the shape in the graph
            NGraphVertex vertex = (map.GetPartFromObject(shape) as NGraphVertex);

            if (vertex == null)
            {
                return;
            }

            // create a visitor which will visit and highlight the graph parts
            NHighlightingVisitor visitor = new NHighlightingVisitor(this);

            visitor.objectMap = map;
            GraphType graphType = (undirectedGraphRadioButton.Checked ? GraphType.Undirected : GraphType.Directed);

            switch (traversalMethodComboBox.SelectedIndex)
            {
            case 0:     // Depth First Traversal
                graph.DepthFirstTraversal(graphType, visitor, vertex);
                break;

            case 1:     // Breadth First Traversal
                graph.BreadthFirstTraversal(graphType, visitor, vertex);
                break;

            case 2:     // Topological Order Traversal (applicable for directed graphs only)
                graph.TopologicalOrderTraversal(visitor);
                break;
            }

            // smart refresh all views
            document.SmartRefreshAllViews();
        }
        private void UpdateHighlights()
        {
            ClearHighlights();

            // get the selected shape
            NShape shape = (view.Selection.AnchorNode as NShape);

            if (shape == null)
            {
                document.SmartRefreshAllViews();
                return;
            }

            // build the graph in which the shape resides
            NGraphBuilder graphBuilder = new NGraphBuilder(new NShapeGraphAdapter(), new NGraphPartFactory());

            NObjectGraphPartMap map;
            NGraph graph = graphBuilder.BuildGraph(shape, out map);

            if (graph == null)
            {
                document.SmartRefreshAllViews();
                return;
            }

            NNodeList shapesToHighlight = new NNodeList();

            switch (shape.ShapeType)
            {
            case ShapeType.Shape2D:

                // 2D shapes are treated as graph vertices, so we must find the vertex in the graph, which
                // represents the shape
                NGraphVertex vertex = (map.GetPartFromObject(shape) as NGraphVertex);
                if (vertex != null)
                {
                    // add edges
                    if (allEdgesCheck.Checked)
                    {
                        shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.Edges, map));
                    }
                    else
                    {
                        if (incommingEdgesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.IncomingEdges, map));
                        }

                        if (outgoingEdgesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.OutgoingEdges, map));
                        }
                    }

                    // add neighbour vertices
                    if (neighbourVerticesCheck.Checked)
                    {
                        shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.NeighbourVertices, map));
                    }
                    else
                    {
                        if (sourceVerticesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.SourceVertices, map));
                        }

                        if (destinationVerticesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.DestinationVertices, map));
                        }
                    }

                    // add accessible vertices
                    if (accessibleVerticesCheck.Checked)
                    {
                        shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.AccessibleVertices, map));
                    }
                    else
                    {
                        if (predecessorVerticesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.PredecessorVertices, map));
                        }

                        if (successorVerticesCheck.Checked)
                        {
                            shapesToHighlight.AddRangeNoDuplicates(GetShapesList(vertex.SuccessorVertices, map));
                        }
                    }
                }
                break;

            case ShapeType.Shape1D:

                // 1D shapes are treated as graph edges, so we must find the edge in the graph, which
                // represents the shape
                NGraphEdge edge = (map.GetPartFromObject(shape) as NGraphEdge);
                if (edge != null)
                {
                    if (fromVertexCheck.Checked)
                    {
                        shapesToHighlight.AddNoDuplicates((NShape)map.GetObjectFromPart(edge.FromVertex));
                    }

                    if (toVertexCheck.Checked)
                    {
                        shapesToHighlight.AddNoDuplicates((NShape)map.GetObjectFromPart(edge.ToVertex));
                    }
                }
                break;
            }

            // highlight the shapes
            foreach (NShape cur in shapesToHighlight)
            {
                cur.Style.FillStyle   = (highlightFillStyle.Clone() as NFillStyle);
                cur.Style.StrokeStyle = (highlightStrokeStyle.Clone() as NStrokeStyle);
            }

            // smart refresh all views
            document.SmartRefreshAllViews();
        }