using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Windows.Forms; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views; using HeuristicLab.EvolutionTracking; using HeuristicLab.MainForm; using HeuristicLab.MainForm.WindowsForms; using HeuristicLab.Visualization; namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { [View("LineageExplorerView")] [Content(typeof(IGenealogyGraph), false)] public partial class SymbolicDataAnalysisExpressionLineageExplorerView : AsynchronousContentView { private readonly ReingoldTilfordLayoutEngine symbolicExpressionTreeNodeLayoutEngine; private readonly Dictionary treeMap; private const int MinHorizontalSpacing = 50; private const int MinVerticalSpacing = 50; private const int PreferredNodeWidth = 80; private const int PreferredNodeHeight = 40; public new IGenealogyGraph Content { get { return (IGenealogyGraph)base.Content; } set { base.Content = value; } } public SymbolicDataAnalysisExpressionLineageExplorerView() { InitializeComponent(); symbolicExpressionTreeNodeLayoutEngine = new ReingoldTilfordLayoutEngine(node => node.Subtrees) { HorizontalSpacing = MinHorizontalSpacing, VerticalSpacing = MinVerticalSpacing, NodeWidth = PreferredNodeWidth, NodeHeight = PreferredNodeHeight }; treeMap = new Dictionary(); double width = symbolicExpressionChartControl.PreferredSize.Width; double height = symbolicExpressionChartControl.PreferredSize.Height; if (symbolicExpressionChartControl.Chart == null) { symbolicExpressionChartControl.Chart = new Chart(0, 0, width, height); } } #region events protected override void OnContentChanged() { base.OnContentChanged(); if (Content != null) { updateTreeView(); } } #endregion protected override void SetEnabledStateOfControls() { base.SetEnabledStateOfControls(); treeView.Enabled = Content != null; } private void updateTreeView() { var lastGen = Content.Ranks.OrderBy(x => x.Key).Last().Value.ToList(); treeMap.Clear(); symbolicExpressionChartControl.Clear(); foreach (var g in lastGen) { var treeNode = new TreeNode(g.Quality.ToString(CultureInfo.InvariantCulture)); treeView.Nodes.Add(treeNode); treeMap.Add(treeNode, (ISymbolicExpressionTree)g.Data); } } private void treeView_AfterSelect(object sender, TreeViewEventArgs e) { symbolicExpressionChartControl.Clear(); var selectedNode = treeView.SelectedNode; var symbolicExpressionTree = treeMap[selectedNode]; var chart = symbolicExpressionChartControl.Chart; var tile = new SymbolicExpressionTreeTile(chart) { LayoutEngine = symbolicExpressionTreeNodeLayoutEngine, PreferredNodeWidth = PreferredNodeWidth, PreferredNodeHeight = PreferredNodeHeight, SymbolicExpressionTree = symbolicExpressionTree }; symbolicExpressionChartControl.UpdateEnabled = false; symbolicExpressionChartControl.Add(tile); // symbolicExpressionChartControl.FlipVertical(); symbolicExpressionChartControl.UpdateEnabled = true; symbolicExpressionChartControl.EnforceUpdate(); } } }