Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.3/SymbolicExpressionView.cs @ 3442

Last change on this file since 3442 was 3442, checked in by gkronber, 14 years ago

Implemented views for DataAnalysisProblems and DataAnalysisSolutions. #938 (Data types and operators for regression problems)

File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Drawing;
5using System.Data;
6using System.Linq;
7using System.Text;
8using System.Windows.Forms;
9using HeuristicLab.MainForm;
10using HeuristicLab.MainForm.WindowsForms;
11
12namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
13  [View("SymbolicExpression View")]
14  [Content(typeof(SymbolicExpressionTree), false)]
15  public partial class SymbolicExpressionView : AsynchronousContentView {
16    public new SymbolicExpressionTree Content {
17      get { return (SymbolicExpressionTree)base.Content; }
18      set { base.Content = value; }
19    }
20
21    public SymbolicExpressionView() {
22      InitializeComponent();
23      Caption = "SymbolicExpression View";
24    }
25
26    public SymbolicExpressionView(SymbolicExpressionTree content)
27      : this() {
28      Content = content;
29    }
30
31
32    protected override void OnContentChanged() {
33      base.OnContentChanged();
34      if (Content == null) {
35        Caption = "SymbolicExpression View";
36        textBox.Text = string.Empty;
37        textBox.Enabled = false;
38      } else {
39        textBox.Text = SymbolicExpression(Content.Root, 0);
40        textBox.Enabled = true;
41      }
42    }
43
44    private static string SymbolicExpression(SymbolicExpressionTreeNode node, int indentLength) {
45      StringBuilder strBuilder = new StringBuilder();
46      strBuilder.Append(' ', indentLength); strBuilder.Append("(");
47      // internal nodes or leaf nodes?
48      if (node.SubTrees.Count > 0) {
49        // symbol on same line as '('
50        strBuilder.AppendLine(node.ToString());
51        // each subtree expression on a new line
52        // and closing ')' also on new line
53        foreach (var subtree in node.SubTrees) {
54          strBuilder.AppendLine(SymbolicExpression(subtree, indentLength + 2));
55        }
56        strBuilder.Append(' ', indentLength); strBuilder.Append(")");
57      } else {
58        // symbol in the same line with as '(' and ')'
59        strBuilder.Append(node.ToString());
60        strBuilder.Append(")");
61      }
62      return strBuilder.ToString();
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.