private void InitialNewGraph(Graph graph) { if (graph == null) return; if (_graph != null) { //TODO:删除旧有的图属性 } _graph = graph; //TODO:Initial graph.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0); Parallel.ForEach<IVertex>(Graph.Vertices, v => { PointF location = new PointF(Random.Next(2, Width - 20), Random.Next(0, Height - 20)); int radio = Random.Next(7, 12); RectangleF bound = new RectangleF(location.X - radio, location.Y - radio, radio * 2, radio*2); v.SetAlgorithmObj(_KH_PANE_LOCATION, location); v.SetAlgorithmObj(_KH_PANE_BOUNDS, bound); v.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0); v.SetAlgorithmObj(Flags.State.None.ToString(), false); v.SetAlgorithmObj(Flags.State.Focus.ToString(), false); v.SetAlgorithmObj(Flags.State.Hover.ToString(), false); v.SetAlgorithmObj(Flags.State.DraggedOver.ToString(), false); v.SetAlgorithmObj(Flags.State.Dragging.ToString(), false); v.SetAlgorithmObj(Flags.State.HighLight.ToString(), false); v.OnAttributeChange += OnAttributeChange; }); Parallel.ForEach<IEdge>(Graph.Edges, e => { e.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0); e.SetAlgorithmObj(Flags.State.None.ToString(), false); e.SetAlgorithmObj(Flags.State.Focus.ToString(), false); e.SetAlgorithmObj(Flags.State.Hover.ToString(), false); e.SetAlgorithmObj(Flags.State.DraggedOver.ToString(), false); e.SetAlgorithmObj(Flags.State.Dragging.ToString(), false); e.SetAlgorithmObj(Flags.State.HighLight.ToString(), false); e.OnAttributeChange += OnAttributeChange; }); graph.OnAddVertex += OnAddVertex; graph.OnAddEdge += OnAddEdge; graph.OnAddType += OnAddType; graph.OnRemoveVertex += OnRemoveVertex; graph.OnRemoveEdge += OnRemoveEdge; graph.OnRemoveType += OnRemoveType; ghelper = new GraphHelper(_graph); System.Timers.Timer t = new System.Timers.Timer(1000);//实例化Timer t.Elapsed += new System.Timers.ElapsedEventHandler(theoutRefresh);//到达时间的时候执行事件; t.AutoReset = true;//设置是执行一次(false)还是一直执行(true); t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件; this.Refresh(); }
private void InitialNewGraph(Graph graph) { if (graph == null) return; if (_graph != null) { //TODO:删除旧有的图属性 } _graph = graph; //TODO:Initial graph.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0); Parallel.ForEach<IVertex>(Graph.Vertices, v => { PointF location = new PointF(Random.Next(2, Width - 20), Random.Next(0, Height - 20)); int radio = Random.Next(7, 12); RectangleF bound = new RectangleF(location.X - radio, location.Y - radio, radio * 2, radio*2); v.SetAlgorithmObj(_KH_PANE_LOCATION, location); v.SetAlgorithmObj(_KH_PANE_BOUNDS, bound); v.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0); v.SetAlgorithmObj(Flags.State.None.ToString(), false); v.SetAlgorithmObj(Flags.State.Focus.ToString(), false); v.SetAlgorithmObj(Flags.State.Hover.ToString(), false); v.SetAlgorithmObj(Flags.State.DraggedOver.ToString(), false); v.SetAlgorithmObj(Flags.State.Dragging.ToString(), false); v.SetAlgorithmObj(Flags.State.HighLight.ToString(), false); v.OnAttributeGhange += OnAttributeChange; }); Parallel.ForEach<IEdge>(Graph.Edges, e => { e.SetAlgorithmObj(_KH_PANE_GRAPH_PRIOR, 0); e.SetAlgorithmObj(Flags.State.None.ToString(), false); e.SetAlgorithmObj(Flags.State.Focus.ToString(), false); e.SetAlgorithmObj(Flags.State.Hover.ToString(), false); e.SetAlgorithmObj(Flags.State.DraggedOver.ToString(), false); e.SetAlgorithmObj(Flags.State.Dragging.ToString(), false); e.SetAlgorithmObj(Flags.State.HighLight.ToString(), false); e.OnAttributeGhange += OnAttributeChange; }); graph.OnAddVertex += OnAddVertex; graph.OnAddEdge += OnAddEdge; graph.OnAddType += OnAddType; graph.OnRemoveVertex += OnRemoveVertex; graph.OnRemoveEdge += OnRemoveEdge; graph.OnRemoveType += OnRemoveType; ghelper = new GraphHelper(_graph); this.Refresh(); }