1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.ComponentModel;
|
---|
4 | using System.Drawing;
|
---|
5 | using System.Data;
|
---|
6 | using System.Drawing.Imaging;
|
---|
7 | using System.Linq;
|
---|
8 | using System.Text;
|
---|
9 | using System.Windows.Forms;
|
---|
10 | using HeuristicLab.Core.Views;
|
---|
11 | using HeuristicLab.MainForm;
|
---|
12 | using Microsoft.Glee.Drawing;
|
---|
13 | using Microsoft.Glee.GraphViewerGdi;
|
---|
14 |
|
---|
15 | namespace HeuristicLab.EvolutionaryTracking {
|
---|
16 | [View("GenealogyGraphView")]
|
---|
17 | [Content(typeof(GenealogyGraph), IsDefaultView = true)]
|
---|
18 | public sealed partial class GenealogyGraphView : ItemView {
|
---|
19 | private readonly GViewer _gViewer;
|
---|
20 |
|
---|
21 | public new GenealogyGraph Content {
|
---|
22 | get { return (GenealogyGraph)base.Content; }
|
---|
23 | set { base.Content = value; }
|
---|
24 | }
|
---|
25 |
|
---|
26 | public GenealogyGraphView()
|
---|
27 | : base() {
|
---|
28 | InitializeComponent();
|
---|
29 | _gViewer = new GViewer() { Dock = DockStyle.Fill };
|
---|
30 | this.Controls.Add(_gViewer);
|
---|
31 | }
|
---|
32 |
|
---|
33 | protected override void DeregisterContentEvents() {
|
---|
34 | // TODO: Deregister your event handlers here
|
---|
35 | base.DeregisterContentEvents();
|
---|
36 | }
|
---|
37 |
|
---|
38 | protected override void RegisterContentEvents() {
|
---|
39 | base.RegisterContentEvents();
|
---|
40 | // TODO: Register your event handlers here
|
---|
41 | }
|
---|
42 |
|
---|
43 | #region Event Handlers (Content)
|
---|
44 | // TODO: Put event handlers of the content here
|
---|
45 | #endregion
|
---|
46 |
|
---|
47 | protected override void OnContentChanged() {
|
---|
48 | base.OnContentChanged();
|
---|
49 | if (Content == null) {
|
---|
50 | // TODO: Add code when content has been changed and is null
|
---|
51 | } else {
|
---|
52 | // TODO: Add code when content has been changed and is not null
|
---|
53 | if (InvokeRequired) {
|
---|
54 | Invoke(new EventHandler(Content_GraphChanged), this, null);
|
---|
55 | } else {
|
---|
56 | SetEnabledStateOfControls();
|
---|
57 | Content_GraphChanged(this, null);
|
---|
58 | }
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | private void Content_GraphChanged(object sender, EventArgs e) {
|
---|
63 | var graph = Content;
|
---|
64 | var nodes = graph.Values;
|
---|
65 | var gleeGraph = new Microsoft.Glee.Drawing.Graph("PopulationGraph") {
|
---|
66 | GraphAttr = {
|
---|
67 | Backgroundcolor = Microsoft.Glee.Drawing.Color.White,
|
---|
68 | NodeAttr = { Shape = Shape.Circle, Label = String.Empty, Padding = 40 },
|
---|
69 | AspectRatio = 2
|
---|
70 | }
|
---|
71 | };
|
---|
72 |
|
---|
73 | foreach (var node in nodes) {
|
---|
74 | var n = gleeGraph.AddNode(node.Id); // Glee does not actually add a new node if the node already exists in the graph
|
---|
75 | n.Attr.Fillcolor = new Microsoft.Glee.Drawing.Color((byte)((1 - node.Quality) * 255), (byte)(255 * node.Quality), 0);
|
---|
76 | n.Attr.Color = new Microsoft.Glee.Drawing.Color((byte)((1 - node.Quality) * 255), (byte)(255 * node.Quality), 0);
|
---|
77 | n.Attr.Label = node.Label;
|
---|
78 | n.Attr.Fontsize = 8;
|
---|
79 | n.Attr.FontName = "Consolas";
|
---|
80 | if (node.IsElite) {
|
---|
81 | n.Attr.Color = Microsoft.Glee.Drawing.Color.DodgerBlue;
|
---|
82 | n.Attr.Shape = Shape.Box;
|
---|
83 | }
|
---|
84 |
|
---|
85 | if (node.OutEdges == null) continue;
|
---|
86 | foreach (var arc in node.OutEdges) {
|
---|
87 | var edge = gleeGraph.AddEdge(node.Id, arc.Target.Id);
|
---|
88 | edge.Attr.LineWidth = 1;
|
---|
89 | byte r = (byte)((edge.SourceNode.Attr.Color.R + edge.TargetNode.Attr.Color.R) / 2);
|
---|
90 | byte g = (byte)((edge.SourceNode.Attr.Color.G + edge.TargetNode.Attr.Color.G) / 2);
|
---|
91 | byte b = (byte)((edge.SourceNode.Attr.Color.B + edge.TargetNode.Attr.Color.B) / 2);
|
---|
92 | edge.Attr.Color = new Microsoft.Glee.Drawing.Color(r, g, b);
|
---|
93 | }
|
---|
94 | }
|
---|
95 | _gViewer.Graph = gleeGraph;
|
---|
96 | _gViewer.Refresh();
|
---|
97 | }
|
---|
98 |
|
---|
99 | protected override void SetEnabledStateOfControls() {
|
---|
100 | base.SetEnabledStateOfControls();
|
---|
101 | // TODO: Enable or disable controls based on whether the content is null or the view is set readonly
|
---|
102 | }
|
---|
103 |
|
---|
104 | #region Event Handlers (child controls)
|
---|
105 | // TODO: Put event handlers of child controls here.
|
---|
106 | #endregion
|
---|
107 | }
|
---|
108 |
|
---|
109 | } |
---|