private void edgeDepthFirstSearchItem_Click(object sender, System.EventArgs e) { if (this.netronPanel.Graph==null) throw new Exception("Generate a graph first"); if (this.netronPanel.Populator==null) throw new Exception("Populator should not be null."); ResetVertexAndEdgeColors(); // create algorithm this.vertexColors=null; this.edgeColors = new EdgeColorDictionary(); EdgeDepthFirstSearchAlgorithm edfs = new EdgeDepthFirstSearchAlgorithm(this.netronPanel.Graph,this.edgeColors); // create tracer LayoutAlgorithmTraverVisitor tracer = new LayoutAlgorithmTraverVisitor(this.netronPanel.Populator); // link to algo edfs.RegisterTreeEdgeBuilderHandlers(tracer); edfs.RegisterEdgeColorizerHandlers(tracer); // add handler to tracers tracer.UpdateVertex +=new ShapeVertexEventHandler(tracer_UpdateVertex); tracer.UpdateEdge +=new ConnectionEdgeEventHandler(tracer_UpdateEdge); // running algorithm Thread thread = new Thread(new ThreadStart(edfs.Compute)); thread.Start(); }
/// <summary> /// Adds an algorithm tracer to the edge dfs algorithm /// </summary> /// <param name="edfs"></param> /// <param name="path"></param> /// <returns>tracer</returns> public AlgorithmTracerVisitor AddTracer(EdgeDepthFirstSearchAlgorithm edfs, string path) { // The visitor that draws the graph at each iteration AlgorithmTracerVisitor vis = new AlgorithmTracerVisitor( (IVertexAndEdgeListGraph)edfs.VisitedGraph, "tr", path, GraphvizImageType.Png); // setting some vertex,edge style options vis.Algo.VertexFormat.Style = GraphvizVertexStyle.Filled; vis.Algo.VertexFormat.FillColor = Color.LightSkyBlue; vis.Algo.FormatVertex += new FormatVertexEventHandler(this.FormatVertex); vis.Algo.FormatEdge += new FormatEdgeEventHandler(this.FormatEdge); edfs.RegisterTreeEdgeBuilderHandlers(vis); edfs.FinishEdge += new EdgeEventHandler(vis.FinishEdge); return vis; }