Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/FragmentGraphView.cs @ 10655

Last change on this file since 10655 was 10655, checked in by bburlacu, 10 years ago

#1772: Made some progress towards the visualization of building block trajectories. Added the FragmentGraphView.

File size: 3.8 KB
Line 
1using System.Collections.Generic;
2using System.Linq;
3using HeuristicLab.Core.Views;
4using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
5using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
6using HeuristicLab.EvolutionTracking;
7using HeuristicLab.MainForm;
8
9namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
10  [View("FragmentGraphView")]
11  [Content(typeof(IGenealogyGraph<IFragment<ISymbolicExpressionTreeNode>>), IsDefaultView = true)]
12  public sealed partial class FragmentGraphView : ItemView {
13    private ReingoldTilfordLayoutEngine<TileLayoutNode> layoutEngine;
14    private ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode> symbolicExpressionEngine;
15
16    private Dictionary<IGenealogyGraphNode<IFragment<ISymbolicExpressionTreeNode>>, TileLayoutNode> tileDictionary;
17
18    private SymbolicExpressionTreeTile Root { get; set; }
19
20    public new IGenealogyGraph<IFragment<ISymbolicExpressionTreeNode>> Content {
21      get { return (IGenealogyGraph<IFragment<ISymbolicExpressionTreeNode>>)base.Content; }
22      set {
23        base.Content = value;
24        MakeTiles();
25      }
26    }
27
28    public FragmentGraphView() {
29      InitializeComponent();
30
31      layoutEngine = new ReingoldTilfordLayoutEngine<TileLayoutNode>(n => n.Children);
32      symbolicExpressionEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>(n => n.Subtrees);
33    }
34
35    private void MakeTiles() {
36      var chart = symbolicExpressionChartControl.Chart;
37      foreach (var node in Content.Nodes.Cast<IGenealogyGraphNode<IFragment<ISymbolicExpressionTreeNode>>>()) {
38        var tile = new SymbolicExpressionTreeTile(chart) {
39          Root = node.Content.Root,
40          LayoutEngine = symbolicExpressionEngine
41        };
42        var tileNode = new TileLayoutNode {
43          Tile = tile
44        };
45        tileDictionary.Add(node, tileNode);
46      }
47
48      foreach (var node in Content.Nodes.Where(n => n.InArcs != null && n.InArcs.Count > 0)) {
49        var graphNode = (IGenealogyGraphNode<IFragment<ISymbolicExpressionTreeNode>>)node;
50        var layoutNode = tileDictionary[graphNode];
51        layoutNode.Children = new List<TileLayoutNode>();
52        foreach (var c in node.InArcs.Select(x => x.Source as IGenealogyGraphNode<IFragment<ISymbolicExpressionTreeNode>>)) {
53          layoutNode.Children.Add(tileDictionary[c]);
54        }
55      }
56    }
57
58    private void Draw() {
59      var root = tileDictionary[(IGenealogyGraphNode<IFragment<ISymbolicExpressionTreeNode>>)Content.Nodes[0]];
60      var visualNodes = layoutEngine.CalculateLayout(root);
61    }
62
63    protected override void DeregisterContentEvents() {
64      // TODO: Deregister your event handlers here
65      base.DeregisterContentEvents();
66    }
67
68    protected override void RegisterContentEvents() {
69      base.RegisterContentEvents();
70      // TODO: Register your event handlers here
71    }
72
73    #region Event Handlers (Content)
74
75    // TODO: Put event handlers of the content here
76
77    #endregion
78
79    protected override void OnContentChanged() {
80      base.OnContentChanged();
81      if (Content == null) {
82        // TODO: Add code when content has been changed and is null
83      } else {
84        // TODO: Add code when content has been changed and is not null
85      }
86    }
87
88
89    protected override void SetEnabledStateOfControls() {
90      base.SetEnabledStateOfControls();
91      // TODO: Enable or disable controls based on whether the content is null or the view is set readonly
92    }
93
94    #region Event Handlers (child controls)
95
96    // TODO: Put event handlers of child controls here.
97
98    #endregion
99  }
100
101  internal class TileLayoutNode {
102    public SymbolicExpressionTreeTile Tile { get; set; }
103    public List<TileLayoutNode> Children { get; set; }
104  }
105}
Note: See TracBrowser for help on using the repository browser.