Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Invoked on each successfully completed iteration of the layout
        /// </summary>
        /// <param name="args"></param>
        private void layout_IterationCompleted(NGraphLayoutCancelEventArguments args)
        {
            if (UpdateDrawingWhileLayouting.Checked)
            {
                bool refreshLocked = view.LockRefresh;
                if (refreshLocked)
                {
                    view.LockRefresh = false;
                }

                NShapeBodyAdapter shapeBodyAdaptor = new NShapeBodyAdapter(document);

                IEnumerator <NGraphPart> en = args.Graph.GetPartsEnumerator();
                while (en.MoveNext())
                {
                    NGraphVertex vertex = en.Current as NGraphVertex;
                    if (vertex != null)
                    {
                        NBody2D body = vertex.Tag as NBody2D;
                        shapeBodyAdaptor.UpdateObjectFromBody2D(body);
                    }
                }

                document.SizeToContent();

                view.Invalidate();
                view.Update();

                if (refreshLocked)
                {
                    view.LockRefresh = true;
                }

                Application.DoEvents();
            }
        }
Ejemplo n.º 3
0
        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();
        }