Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/18/11 10:55:20 (14 years ago)
Author:
mkommend
Message:

#1418: Adapted views to new symbolic expression tree encoding.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r5473 r5513  
    2424using System.Drawing;
    2525using System.Drawing.Imaging;
     26using System.Linq;
    2627using System.Windows.Forms;
    2728
     
    3031    private Image image;
    3132    private StringFormat stringFormat;
    32     private Dictionary<SymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes;
     33    private Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes;
    3334
    3435    public SymbolicExpressionTreeChart() {
     
    4445    }
    4546
    46     public SymbolicExpressionTreeChart(SymbolicExpressionTree tree)
     47    public SymbolicExpressionTreeChart(ISymbolicExpressionTree tree)
    4748      : this() {
    4849      this.Tree = tree;
     
    8586    }
    8687
    87     private SymbolicExpressionTree tree;
    88     public SymbolicExpressionTree Tree {
     88    private ISymbolicExpressionTree tree;
     89    public ISymbolicExpressionTree Tree {
    8990      get { return this.tree; }
    9091      set {
    9192        tree = value;
    92         visualTreeNodes = new Dictionary<SymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode>();
     93        visualTreeNodes = new Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode>();
    9394        if (tree != null) {
    9495          foreach (SymbolicExpressionTreeNode node in tree.IterateNodesPrefix())
     
    129130    }
    130131
    131     public VisualSymbolicExpressionTreeNode GetVisualSymbolicExpressionTreeNode(SymbolicExpressionTreeNode symbolicExpressionTreeNode) {
     132    public VisualSymbolicExpressionTreeNode GetVisualSymbolicExpressionTreeNode(ISymbolicExpressionTreeNode symbolicExpressionTreeNode) {
    132133      if (visualTreeNodes.ContainsKey(symbolicExpressionTreeNode))
    133134        return visualTreeNodes[symbolicExpressionTreeNode];
     
    207208
    208209    #region methods for painting the symbolic expression tree
    209     private void DrawFunctionTree(SymbolicExpressionTree tree, Graphics graphics, int x, int y, int width, int height) {
     210    private void DrawFunctionTree(ISymbolicExpressionTree tree, Graphics graphics, int x, int y, int width, int height) {
    210211      DrawFunctionTree(tree.Root, graphics, x, y, width, height, Point.Empty);
    211212    }
     
    220221    /// <param name="width">width of drawing area</param>
    221222    /// <param name="height">height of drawing area</param>
    222     private void DrawFunctionTree(SymbolicExpressionTreeNode node, Graphics graphics, int x, int y, int width, int height, Point connectionPoint) {
     223    private void DrawFunctionTree(ISymbolicExpressionTreeNode node, Graphics graphics, int x, int y, int width, int height, Point connectionPoint) {
    223224      VisualSymbolicExpressionTreeNode visualTreeNode = visualTreeNodes[node];
    224225      float center_x = x + width / 2;
     
    262263
    263264      //draw terminal node
    264       if (node.SubTrees.Count == 0) {
     265      if (node.SubTrees.Count() == 0) {
    265266        graphics.FillRectangle(nodeFillBrush, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
    266267        graphics.DrawRectangle(nodeLinePen, visualTreeNode.X, visualTreeNode.Y, visualTreeNode.Width, visualTreeNode.Height);
     
    280281      //calculate areas for the subtrees according to their tree size and call drawFunctionTree
    281282      Point connectFrom = new Point(visualTreeNode.X + visualTreeNode.Width / 2, visualTreeNode.Y + visualTreeNode.Height);
    282       int[] xBoundaries = new int[node.SubTrees.Count + 1];
     283      int[] xBoundaries = new int[node.SubTrees.Count() + 1];
    283284      xBoundaries[0] = x;
    284       for (int i = 0; i < node.SubTrees.Count; i++) {
    285         xBoundaries[i + 1] = (int)(xBoundaries[i] + (width * (double)node.SubTrees[i].GetSize()) / (node.GetSize() - 1));
    286         DrawFunctionTree(node.SubTrees[i], graphics, xBoundaries[i], y + height,
     285      for (int i = 0; i < node.SubTrees.Count(); i++) {
     286        xBoundaries[i + 1] = (int)(xBoundaries[i] + (width * (double)node.SubTrees.ElementAt(i).GetSize()) / (node.GetSize() - 1));
     287        DrawFunctionTree(node.SubTrees.ElementAt(i), graphics, xBoundaries[i], y + height,
    287288          xBoundaries[i + 1] - xBoundaries[i], height, connectFrom);
    288289      }
Note: See TracChangeset for help on using the changeset viewer.