[10514] | 1 | using System.Collections.Generic;
|
---|
| 2 | using System.Globalization;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Windows.Forms;
|
---|
| 5 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 6 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
|
---|
| 7 | using HeuristicLab.EvolutionTracking;
|
---|
| 8 | using HeuristicLab.MainForm;
|
---|
| 9 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 10 | using HeuristicLab.Visualization;
|
---|
| 11 |
|
---|
| 12 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
|
---|
| 13 | [View("LineageExplorerView")]
|
---|
| 14 | [Content(typeof(IGenealogyGraph), false)]
|
---|
| 15 | public partial class SymbolicDataAnalysisExpressionLineageExplorerView : AsynchronousContentView {
|
---|
[10517] | 16 | private readonly ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionTreeNodeLayoutEngine;
|
---|
[10514] | 17 |
|
---|
[10517] | 18 | private readonly Dictionary<TreeNode, ISymbolicExpressionTree> treeMap;
|
---|
[10514] | 19 |
|
---|
| 20 | private const int MinHorizontalSpacing = 50;
|
---|
| 21 | private const int MinVerticalSpacing = 50;
|
---|
| 22 | private const int PreferredNodeWidth = 80;
|
---|
| 23 | private const int PreferredNodeHeight = 40;
|
---|
| 24 |
|
---|
| 25 | public new IGenealogyGraph Content {
|
---|
| 26 | get { return (IGenealogyGraph)base.Content; }
|
---|
| 27 | set { base.Content = value; }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | public SymbolicDataAnalysisExpressionLineageExplorerView() {
|
---|
| 31 | InitializeComponent();
|
---|
[10650] | 32 | symbolicExpressionTreeNodeLayoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(node => node.Subtrees) {
|
---|
[10524] | 33 | HorizontalSpacing = MinHorizontalSpacing,
|
---|
| 34 | VerticalSpacing = MinVerticalSpacing,
|
---|
| 35 | NodeWidth = PreferredNodeWidth,
|
---|
| 36 | NodeHeight = PreferredNodeHeight
|
---|
[10514] | 37 | };
|
---|
[10650] | 38 |
|
---|
[10517] | 39 | treeMap = new Dictionary<TreeNode, ISymbolicExpressionTree>();
|
---|
[10655] | 40 | double width = symbolicExpressionChartControl.PreferredSize.Width;
|
---|
| 41 | double height = symbolicExpressionChartControl.PreferredSize.Height;
|
---|
| 42 | if (symbolicExpressionChartControl.Chart == null) {
|
---|
| 43 | symbolicExpressionChartControl.Chart = new Chart(0, 0, width, height);
|
---|
[10514] | 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | #region events
|
---|
| 48 | protected override void OnContentChanged() {
|
---|
| 49 | base.OnContentChanged();
|
---|
| 50 | if (Content != null) { updateTreeView(); }
|
---|
| 51 | }
|
---|
| 52 | #endregion
|
---|
| 53 |
|
---|
| 54 | protected override void SetEnabledStateOfControls() {
|
---|
| 55 | base.SetEnabledStateOfControls();
|
---|
| 56 | treeView.Enabled = Content != null;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | private void updateTreeView() {
|
---|
| 60 | var lastGen = Content.Ranks.OrderBy(x => x.Key).Last().Value.ToList();
|
---|
[10517] | 61 | treeMap.Clear();
|
---|
[10655] | 62 | symbolicExpressionChartControl.Clear();
|
---|
[10514] | 63 | foreach (var g in lastGen) {
|
---|
| 64 | var treeNode = new TreeNode(g.Quality.ToString(CultureInfo.InvariantCulture));
|
---|
| 65 | treeView.Nodes.Add(treeNode);
|
---|
[10517] | 66 | treeMap.Add(treeNode, (ISymbolicExpressionTree)g.Content);
|
---|
[10514] | 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | private void treeView_AfterSelect(object sender, TreeViewEventArgs e) {
|
---|
[10655] | 71 | symbolicExpressionChartControl.Clear();
|
---|
[10514] | 72 | var selectedNode = treeView.SelectedNode;
|
---|
[10517] | 73 | var symbolicExpressionTree = treeMap[selectedNode];
|
---|
[10655] | 74 | var chart = symbolicExpressionChartControl.Chart;
|
---|
[10517] | 75 | var tile = new SymbolicExpressionTreeTile(chart) {
|
---|
| 76 | LayoutEngine = symbolicExpressionTreeNodeLayoutEngine,
|
---|
[10514] | 77 | PreferredNodeWidth = PreferredNodeWidth,
|
---|
[10517] | 78 | PreferredNodeHeight = PreferredNodeHeight,
|
---|
| 79 | SymbolicExpressionTree = symbolicExpressionTree
|
---|
[10514] | 80 | };
|
---|
[10655] | 81 | symbolicExpressionChartControl.UpdateEnabled = false;
|
---|
| 82 | symbolicExpressionChartControl.Add(tile);
|
---|
[10728] | 83 | // symbolicExpressionChartControl.FlipVertical();
|
---|
[10655] | 84 | symbolicExpressionChartControl.UpdateEnabled = true;
|
---|
| 85 | symbolicExpressionChartControl.EnforceUpdate();
|
---|
[10514] | 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|